自动获取到的IP改到固定IP里?[已解决]
本帖最后由 流沙枫 于 2012-3-14 10:34 编辑;16进制的0x10加上16进制的0x20=10进制的16+32=48
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
;"."取代了原代码中的"winmgmts:\\&$strComputer&\root\CIMV2"的$strComputer
$strComputer = "."
;具体作用不是很明白,本人的理解是“获取对象”
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 48)
;$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem");没看出这行在这里起什么作用
;“获取对象”
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 48)
;获取当前的IP地址
For $objItem In $colItems
$LocalIP = $objItem.IPAddress(0);获取IP地址
$LocalSubnetmask = $objItem.IPSubnet(0);获取子网掩码
$LocalGateway = $objItem.DefaultIPGateway(0);获取默认网关
$LocalDns1 = $objItem.DNSServerSearchOrder(0);获取首选DNS服务器
$LocalDns2 = $objItem.DNSServerSearchOrder(1);获取备选DNS服务器
Next
;修改IP地址代码
If IsObj($colItems) Then;猜这行作用是:如果找到网卡信息就开始修改
For $objItem In $colItems
$objItem.EnableStatic($LocalIP, $LocalSubnetmask);修改IP地址及子网掩码
$objItem.SetGateways($LocalGateway);修改默认网关
$objItem.SetDNSServerSearchOrder($LocalDns1);修改首选及备选DNS服务器
Next
EndIf
;预设置的IP地址
;Dim $SetIPAddress
;$SetIPAddress =$objItem.IPAddress(0)
;预设置的子网掩码
;Dim $SetSubnetmask
;$SetSubnetmask = $objItem.IPSubnet(0)
;预设置的默认网关
;Dim $SetGateway
;$SetGateway = $objItem.DefaultIPGateway(0)
;首选及备选DNS服务器
;Dim $SetDns = [$objItem.DNSServerSearchOrder(0), $objItem.DNSServerSearchOrder(1)]
无效的?
。。。。。。。 回复 1# 流沙枫
楼主代码哪来的?你确定修改这几项就OK吗?我这边不好测试,你的代码我整理了下,说实话我也很关心这个问题,请反馈成功与否
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
$colItem0 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL",48)
For $objItem In $colItems
$objItem.EnableStatic($objItem.IPAddress(0), $objItem.IPSubnet(0));修改IP地址及子网掩码
$objItem.SetGateways($objItem.DefaultIPGateway(0);修改默认网关
$objItem.SetDNSServerSearchOrder($objItem.DNSServerSearchOrder(0));修改首选及备选DNS服务器
Next
回复 2# 502762378
还是不行..... http://sky123.org/forum.php?mod=viewthread&tid=166737&fromuid=60509
ppsfxn 发表于 2012-3-8 10:37 http://www.autoitx.com/images/common/back.gif
这个不适合我吧?
我的是想要每一台机获取自动IP后,再把得到的IP改为固定的。。。。
你给的只是获取网络上的IP和MAC地址,这个路由都可以得到了!! 不明白,目的何在,既然能自动获取....还要固定? 回复 7# au3x
其实楼主就是想把系统分配的IP设为固定IP 回复au3x
其实楼主就是想把系统分配的IP设为固定IP
502762378 发表于 2012-3-10 15:40 http://www.autoitx.com/images/common/back.gif
握爪...... 以前写的,调用devcon,参考一下
#include <ACN_NET.au3>
#include<process.au3>
Break(0)
TrayTip(" 初始化信息 ", "重启网卡中请稍等…", 120, 1)
Dim $i
While $i < 6
$m = _RunDOS('' netsh interface ip set address name = "本地连接" '' & $i & '' source = dhcp'')
$n = _RunDOS('' netsh interface ip set dns "本地连接" '' & $i & '' source = dhcp'')
$i += 1
WEnd
RunWait("devcon restart =net pci\*", "", @SW_HIDE)
Sleep(3000)
TrayTip(" 正在获取DHCP信息 ", " 完成进度的30%…请稍候", 120, 1)
$info = _NetworkAdapterInfo()
$T1 = $info;IP地址
$T2 = $info;子网掩码
$T3 = $info;默认网关
$T4 = $info;主DNS
$T5 = $info;次DNS
$T6 = $info;网卡名称
$T7 = $info;主机名称
$T8 = $info;MAC地址
$T9 = $info;连接名称
MsgBox(1, "", "网卡名称:" & $T6 & @CRLF & "连接名称:" & $T9 & @CRLF & "主机名称:" & $T7 & @CRLF & "IP地址:" & $T1 & @CRLF & "子网掩码:" & $T2 & @CRLF & "默认网关:" & $T3 & @CRLF & "主DNS:" & $T4 & @CRLF & "次DNS:" & $T5 & @CRLF & "MAC地址:" & $T8, 3)
Sleep(1000)
TrayTip(" 正在设置固定IP ", "完成进度的60%…请稍候", 120, 1)
_WMI_SetNetworkAdapterInfo(@ComputerName, $T1, $T2, $T3, $T4, $T5, 0)
Sleep(3000)
Dim $Tip = @IPAddress1
Dim $Nip = StringSplit($Tip, ".")
TrayTip(" 正在设置机器名", " 完成进度的90%…请稍候", 120, 1)
Dim $NewName = "LPXX_" & Int(StringFormat("%03d\n", $Nip))
Sleep(1000)
$_Return = DllCall("Kernel32.dll", "int", "SetComputerNameEx", "int", 5, "str", $NewName)
If $_Return <> 0 Then MsgBox(0, "", "新的主机器名是:" & $NewName & @LF & "建议重启电脑生效!", 2)
TrayTip("结束", "完成进度的100%,所有信息设置完毕", 0)
Exit
楼主不厚道,原来是ACN的UDF 以前写的,调用devcon,参考一下
lpxx 发表于 2012-3-10 23:45 http://www.autoitx.com/images/common/back.gif
明天到机房再试下。。。。。 楼主不厚道,原来是ACN的UDF
502762378 发表于 2012-3-11 00:17 http://www.autoitx.com/images/common/back.gif
我没说不是啊。。。。
都是先搜索,再把找到的代码改下!! 以前写的,调用devcon,参考一下
lpxx 发表于 2012-3-10 23:45 http://www.autoitx.com/images/common/back.gif
错误: 表达式错误?
$m = _RunDOS('' netsh
~~~~~~~~~~~~~~~~~^ 以前写的,调用devcon,参考一下
lpxx 发表于 2012-3-10 23:45 http://www.autoitx.com/images/common/back.gif
$m = _RunDOS(' netsh interface ip set address name = "本地连接" ' & $i & ' source = dhcp')
$n = _RunDOS(' netsh interface ip set dns "本地连接" ' & $i & ' source = dhcp')
改成这样通过编译了.... #include <ACN_NET.au3>
#include<process.au3>
Break(0)
TrayTip(" 初始化信息 ", "重启网卡中请稍等…", 120, 1)
Dim $i
While $i < 6
$m = _RunDOS(' netsh interface ip set address name = "本地连接" ' & $i & ' source = dhcp')
$n = _RunDOS(' netsh interface ip set dns "本地连接" ' & $i & ' source = dhcp')
$i += 1
WEnd
RunWait("devcon restart =net pci\*", "", @SW_HIDE)
Sleep(3000)
TrayTip(" 正在获取DHCP信息 ", " 完成进度的30%…请稍候", 120, 1)
$info = _NetworkAdapterInfo()
$T1 = $info;IP地址
$T2 = $info;子网掩码
$T3 = $info;默认网关
$T4 = $info;主DNS
$T5 = $info;次DNS
$T6 = $info;网卡名称
$T7 = $info;主机名称
$T8 = $info;MAC地址
$T9 = $info;连接名称
MsgBox(1, "", "网卡名称:" & $T6 & @CRLF & "连接名称:" & $T9 & @CRLF & "主机名称:" & $T7 & @CRLF & "IP地址:" & $T1 & @CRLF & "子网掩码:" & $T2 & @CRLF & "默认网关:" & $T3 & @CRLF & "主DNS:" & $T4 & @CRLF & "次DNS:" & $T5 & @CRLF & "MAC地址:" & $T8, 3)
Sleep(1000)
TrayTip(" 正在设置固定IP ", "完成进度的60%…请稍候", 120, 1)
_WMI_SetNetworkAdapterInfo(@ComputerName, $T1, $T2, $T3, $T4, $T5, 0)
Sleep(3000)
Dim $Tip = @IPAddress1
Dim $Nip = StringSplit($Tip, ".")
TrayTip(" 正在设置机器名", " 完成进度的90%…请稍候", 120, 1)
Dim $NewName = "LPXX_" & Int(StringFormat("%03d\n", $Nip))
Sleep(1000)
$_Return = DllCall("Kernel32.dll", "int", "SetComputerNameEx", "int", 5, "str", $NewName)
If $_Return <> 0 Then MsgBox(0, "", "新的主机器名是:" & $NewName & @LF & "建议重启电脑生效!", 2)
TrayTip("结束", "完成进度的100%,所有信息设置完毕", 0)
Exit可以了,thanks....
页:
[1]
2