蓝色动力网络

 找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3702|回复: 2

简单的IP修改 一看就明白(高手别见笑了)

[复制链接]
发表于 2009-10-25 10:14:45 | 显示全部楼层 |阅读模式
#include <GUIConstants.au3>
#include <GuiIPAddress.au3>
;获取网卡相关的信息
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")         
For $objItem In $colItems
;获取网关
$LocalGateway = $objItem.DefaultIPGateway(0)
;获取计算机名
$LoaclHostName =$objItem.DNSHostName
;获取IP地址
$LocalIP=$objItem.IPAddress(0)
;获取DNS首选
$LocalDns1 = $objItem.DNSServerSearchOrder(0)
;获取DNS备用
$LocalDns2 = $objItem.DNSServerSearchOrder(1)
;获取子掩网码
$LocalSubnetmask = $objItem.IPSubnet(0)
;获取网卡名称
$b = $objItem.Description
;获取MAC地址
$MAC1 = $objItem.MACAddress
Next
Local $index = 3

$Form1 = GUICreate("IP地址修改器", 394, 366, 301, 157)
F()
$Tab1 = GUICtrlCreateTab(8, 8, 377, 313)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("IP修改")
$Label1 = GUICtrlCreateLabel("如果网络支持此功能,刚可以获取自动指派的 IP 设置。否则,", 24, 40, 332, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("您需要从网络系统管理员处获得适当的 IP 设置。", 24, 64, 260, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("设置下面的IP地址(S):", 24, 88, 345, 113)
$Label3 = GUICtrlCreateLabel("IP  地址:", 48, 112, 72, 17)
$Label4 = GUICtrlCreateLabel("子网掩码:", 48, 144, 64, 17)
$Label5 = GUICtrlCreateLabel("默认风关:", 48, 176, 64, 17)
$Input1 = _GUICtrlIpAddressCreate ($Form1, 176, 112, 153, 21)
_GUICtrlIpAddressSet ($Input1,$LocalIP)
$Input2 = _GUICtrlIpAddressCreate ($Form1, 176, 140, 153, 21)
_GUICtrlIpAddressSet ($Input2, $LocalSubnetmask)
$Input3 = _GUICtrlIpAddressCreate ($Form1, 176, 168, 153, 21)
_GUICtrlIpAddressSet ($Input3, $LocalGateway)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("设置下面的 DNS 服务器地址(E):", 24, 208, 345, 97)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("首选 DNS 服务器:", 48, 240, 105, 17)
$Label7 = GUICtrlCreateLabel("备用 DNS 服务器:", 48, 272, 105, 17)
$Input4 = _GUICtrlIpAddressCreate ($Form1, 176, 232, 153, 21)
_GUICtrlIpAddressSet ($Input4,$LocalDns1)
$Input5 = _GUICtrlIpAddressCreate ($Form1, 176, 264, 153, 21)
_GUICtrlIpAddressSet ($Input5,$LocalDns2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateTabItem("")
$Button1 = GUICtrlCreateButton("确定", 128, 328, 75, 25, 0)
$Button2 = GUICtrlCreateButton("取消", 216, 328, 75, 25, 0)
$Button3 = GUICtrlCreateButton("应用", 304, 328, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1
                        _SetIpEditState(0)
                        _MQ($Input1,$Input2,$Input3,$Input4,$Input5)
                        _SetIpEditState(1)
                        Exit
               
                Case $Button3
                        _SetIpEditState(0)
                        _MQ($Input1,$Input2,$Input3,$Input4,$Input5)
                        _SetIpEditState(1)
                        MsgBox(64,"提示","IP相关修改完成!")

                Case $Button2
                        Exit
        EndSwitch        
WEnd

Func _MQ($IP,$mas,$GW,$Dns1,$Dns2)
$ipAdd = _GUICtrlIpAddressGet($IP)
$Mask = _GUICtrlIpAddressGet($mas)
$Gateway = _GUICtrlIpAddressGet($GW)
Dim $LocalIPAddress[1] = [$ipAdd]
Dim $strSubnetMask[1] = [$Mask]
Dim $strGateway[1] = [$Gateway]
Dim $strGatewayMetric[1] = [1]
Dim $strdns[2]
$strdns[0]= _GUICtrlIpAddressGet($Dns1)
$strdns[1]= _GUICtrlIpAddressGet($Dns2)
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")        
If IsObj($colItems) Then
        For $objNetAdapter in $colItems
                $objNetAdapter.EnableStatic($LocalIPAddress,$strSubnetMask)
                    $objNetAdapter.SetGateways($strGateway)
                    $objNetAdapter.SetDNSServerSearchOrder($strdns)
        Next
Endif
EndFunc

Func _SetIpEditState($s=1)
   For $i=2 To 21
      If $s=0 Then
                  ControlDisable("","","Edit" & $i)
      Else
                ControlEnable("","","Edit"& $i)
      EndIf
   Next
EndFunc
发表于 2010-1-12 15:01:02 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

发表于 2010-1-12 15:01:20 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

蓝色动力网络微信平台
网站管理,业务合作联系邮箱: admin#lansedongli.com    QQ:13412492 限网站业务问题.
网站帐号、密码、密保找回请使用注册邮箱,发送邮件至 password#lansedongli.com ,否则不予受理.
免责声明:本论坛所有文字和图片仅代表其个人观点.
本站某些资料或文章来自于互联网,不代表本站观点,如果侵犯了您的权益,请来信告知,我们会在三天内删除.
为了给大家一个更好的交流场所,请勿在本论坛发表与中华人民共和国法律相抵触的言论,请合作,谢谢!
Copyright © 2007-2019 Corporation Powered by网吧系统 版权所有    转载请注明!
浙ICP备11043737号-1 程序:Discuz! x3.4

湘公网安备 43018102000145号

手机版|Archiver|蓝色动力网络   

快速回复 返回顶部 返回列表