當前位置:編程學習大全網 - 編程語言 - 求壹個小程序,自動填寫IP?

求壹個小程序,自動填寫IP?

能說的詳細點麼?

如果是自動輸入這些的話,可以用工具2KXP,這個設置好了以後只需要輸入機器號就可以自動寫好IP和機器命。

如果是不同的機器輸入不同的IP。 首先需要MAC地址對應的IP地址表,然後通過讀取MAC地址來填寫IP。變成如下:

On Error Resume Next

'取得本機器的網卡物理地址: MacAddress

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{ impersonationLevel=impersonate }!\\" & strComputer & "\root\cimv2")

Set colNicConfigs = objWMIService.ExecQuery _

("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For Each objNicConfig In colNicConfigs

Set objNic = objWMIService.Get _

("Win32_NetworkAdapter.DeviceID=" & objNicConfig.Index)

'本機器的網卡物理地址寫入變量 : strMacAddress

strMacAddress = objNic.MACAddress

Next

'讀取配置文件

dim files,file,strReadLine ,RowNumber, isFind

isFind=0

Const ForReading = 1

set files=CreateObject("Scripting.FileSystemObject")

if files.fileexists("config.cfg", ForReading) then

set file=files.opentextfile("config.cfg")

else

msgbox("請在程序目錄下放置MAC列表文件(文件名為:config.cfg)")

end if

RowNumber = 0

Do While file.AtEndOfStream <> True

strReadLine = file.ReadLine

RowNumber = RowNumber + 1

If InStr(strReadLine,strMacAddress) <> 0 Then

ComputerConfig = Split(strReadLine , ";")

isFind=1

Exit Do

End If

Loop

If isFind=1 Then

'修改IP地址

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _

("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array(ComputerConfig(2))

strSubnetMask = Array("255.255.255.0")

strGateway = Array(ComputerConfig(3))

strDNS = Array("202.100.64.68","202.101.103.55")

strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters

errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)

Next

'修改機器名

Set WshShell = CreateObject("Wscript.Shell")

Set Fso = CreateObject("SCripting.FileSystemObject")

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", ComputerConfig(0) ,"REG_SZ"

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", ComputerConfig(0) ,"REG_SZ"

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname", ComputerConfig(0) ,"REG_SZ"

'修改CS-CDKEY

WshShell.RegWrite "HKCU\Software\Valve\CounterStrike\Settings\Key", ComputerConfig(4),"REG_SZ"

WshShell.RegWrite "HKU\S-1-5-21-839522115-507921405-2146800195-500\Software\Valve\CounterStrike\Settings\Key", ComputerConfig(4),"REG_SZ"

WshShell.RegWrite "HKU\S-1-5-21-1085031214-220523388-839522115-500\Software\Valve\CounterStrike\Settings\Key", ComputerConfig(4),"REG_SZ"

WshShell.RegWrite "HKU\S-1-5-21-1614895754-1417001333-839522115-500\Software\Valve\CounterStrike\Settings\key", ComputerConfig(4),"REG_SZ"

'清除啟動項

WshShell.RegDelete"HKLM\Software\Microsoft\Windows\CurrentVersion\Run\AutoConfig"

Set Wshell=Nothing

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{ impersonationLevel=impersonate,(Shutdown) }!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _

("Select * from Win32_OperatingSystem")

If errEnable = 0 Then

'WScript.Echo "網絡配置完成,重啟後生效!!"

Else

WScript.Echo "配置失敗"

End If

For Each objOperatingSystem in colOperatingSystems

'ObjOperatingSystem.Reboot()

Next

On Error GoTo 0

Else

msgbox("本機MAC地址在列表文件中沒有找到!")

End If

還有壹個config.cfg的文件,內容如下:

[ComputerName] [MacAddress] [IPAddress] [GateWay] [CS:CDKey]

LSDL001;00:11:5B:CF:C8:12;192.168.0.1;192.168.0.254;3245164654063

LSDL002;00:11:5B:BD:2F:E4;192.168.1.1;192.168.1.254;3385636230783

LSDL003;00:11:5B:B3:F0:86;192.168.2.1;192.168.2.254;2030698167302

LSDL004;00:11:5B:C8:C8:E1;192.168.3.1;192.168.3.254;7149496192146

LSDL005;00:11:5B:CF:C6:D9;192.168.4.1;192.168.4.254;6823878707810

WJY;00:11:11:02:FA:F3;192.168.4.1;192.168.4.254;6823878707810

  • 上一篇:學編程到底是在學什麽?
  • 下一篇:什麽是側銑頭,都有哪些種類?
  • copyright 2024編程學習大全網