找回密码
 加入
搜索
查看: 7379|回复: 18

[网络通信] au3 怎么才能添加多个IP?

 火.. [复制链接]
发表于 2010-8-20 14:17:49 | 显示全部楼层 |阅读模式
au3 怎么才能添加多个IP?
这个是修改1个IP,怎么才能在现有网卡,现有IP的基础上载加个IP地址啊
Dim $SetIPAddress[1]
$Config_IPAddress = "10.1.1.1"
$Config_Subnetmask = "255.0.0.0"
$SetIPAddress[0] = $Config_IPAddress
Dim $SetSubnetmask[1]
$SetSubnetmask[0] = $Config_Subnetmask
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "localhost"
$colItems = ""
$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($SetIPAddress, $SetSubnetmask)
                ;$objNetAdapter.SetGateways ($SetGateway)
                ;$objNetAdapter.SetDNSServerSearchOrder ($SetDns)
        Next
EndIf


谢谢大家了,我急用啊!
发表于 2010-8-20 14:52:42 | 显示全部楼层
Dim $SetIPAddress[2]
$SetIPAddress[0] = "192.168.1.198"
$SetIPAddress[1] = "192.168.1.199"
Dim $SetSubnetmask[2]
$SetSubnetmask[0] = "255.255.255.0"
$SetSubnetmask[1] = "255.255.255.0"


$objWMIService = ObjGet("winmgmts:\" & "." & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
                0x10 + 0x20)
$colComputers = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
        For $objNetAdapter In $colItems
                $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
        Next
EndIf

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-8-20 14:59:32 | 显示全部楼层
多一个IP。必须再多一个掩码。

想设置多少个都可以。
发表于 2010-8-20 15:01:27 | 显示全部楼层
本帖最后由 xsjtxy 于 2010-8-20 15:03 编辑
Dim $SetIPAddress[5]
$SetIPAddress[0] = "192.168.1.195"
$SetIPAddress[1] = "192.168.1.196"
$SetIPAddress[2] = "192.168.1.197"
$SetIPAddress[3] = "192.168.1.198"
$SetIPAddress[4] = "192.168.1.199"
Dim $SetSubnetmask[5]
$SetSubnetmask[0] = "255.255.255.0"
$SetSubnetmask[1] = "255.255.255.0"
$SetSubnetmask[2] = "255.255.255.0"
$SetSubnetmask[3] = "255.255.255.0"
$SetSubnetmask[4] = "255.255.255.0"


$objWMIService = ObjGet("winmgmts:\" & "." & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
$colComputers = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
        For $objNetAdapter In $colItems
                $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
        Next
EndIf
 楼主| 发表于 2010-8-20 16:18:25 | 显示全部楼层
那么我怎么设置第一IP,是本机默认IP,只修改第2个ip,第一IP默认不动,怎么写啊,谢谢了,我急用啊
发表于 2010-8-20 16:21:35 | 显示全部楼层
帮人帮到头
Dim $SetIPAddress[2]
$SetIPAddress[0] = @IPAddress1
$SetIPAddress[1] = "192.168.1.199"
Dim $SetSubnetmask[2]
$SetSubnetmask[0] = "255.255.255.0"
$SetSubnetmask[1] = "255.255.255.0"


$objWMIService = ObjGet("winmgmts:\" & "." & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
                0x10 + 0x20)
$colComputers = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
        For $objNetAdapter In $colItems
                $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
        Next
EndIf
 楼主| 发表于 2010-8-20 19:34:55 | 显示全部楼层
现在是IP可以改了,子网掩码还得修改,怎么才能让第一个子网掩码变成默认的啊
Dim $SetIPAddress[2]
$SetIPAddress[0] = @IPAddress1
$SetIPAddress[1] = "192.168.1.199"
Dim $SetSubnetmask[2]
$SetSubnetmask[0] = "255.255.255.0"
$SetSubnetmask[1] = "255.255.255.0"


$objWMIService = ObjGet("winmgmts:\\" & "." & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
                0x10 + 0x20)
$colComputers = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
        For $objNetAdapter In $colItems
                $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
        Next
EndIf


$SetSubnetmask[0] = "255.255.255.0"
发表于 2010-8-20 20:33:46 | 显示全部楼层
回复 7# bj17209


    默认的是什么意思?
发表于 2010-8-21 10:38:24 | 显示全部楼层
WMI修改IP需要重启生效吗?
 楼主| 发表于 2010-8-21 12:32:23 | 显示全部楼层
也就是,不修改机器本身的第一个IP和第一个ip的子网掩码啊,就修改第2个的ip和子网掩码啊,帮帮我啊,急用啊
发表于 2010-8-21 12:41:17 | 显示全部楼层
获取子网可以通过ipconfig /all来。如果纯AU3无法获取的话
 楼主| 发表于 2010-8-21 13:06:37 | 显示全部楼层
Dim $SetIPAddress[2]
$SetIPAddress[0] = @IPAddress1
$SetIPAddress[1] = "192.168.1.199"
Dim $SetSubnetmask[2]
$SetSubnetmask[0] = "255.255.255.0" 怎么才能不用修改啊!!
$SetSubnetmask[1] = "255.255.255.0"
就想IP1一样不用修改
发表于 2010-8-21 14:17:47 | 显示全部楼层
本帖最后由 xsjtxy 于 2010-8-21 14:39 编辑
#include <Constants.au3>

Dim $SetIPAddress[2]
$SetIPAddress[0] = @IPAddress1
$SetIPAddress[1] = "192.168.1.199"


$foo = Run(@SystemDir&"\ipconfig.exe", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($foo)
$text=StdoutRead($foo)
$text=StringTrimLeft($text, StringInStr($text, "Subnet Mask")+35)
$text=StringLeft($text, StringInStr($text, " ")-4)



if StringLen($text) < 8 then $text = "255.255.255.0"

Dim $SetSubnetmask[2]
$SetSubnetmask[0] = $text
$SetSubnetmask[1] = "255.255.255.0"


$objWMIService = ObjGet("winmgmts:\" & "." & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
$colComputers = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
        For $objNetAdapter In $colItems
                $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
        Next
EndIf
发表于 2010-8-22 01:45:04 | 显示全部楼层
留脚印学习,感谢分享
发表于 2010-8-22 10:46:47 | 显示全部楼层
学习了,IP地址添加
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 07:49 , Processed in 0.155269 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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