我有一批服务器更改了网络环境,需要批量修改IP。现在需要写一个批量远程修改IP的批处理脚本。请问如何写?
发布网友
发布时间:2022-05-04 01:22
我来回答
共3个回答
热心网友
时间:2023-10-21 19:48
ChangeIP "192.168.1.2", "255.255.255.0", "192.168.1.1", "192.168.1.1", "192.168.2.1"
'Function ChangeIP (IP As String,NM As String,GW As String,MDNS As String,SDNS As String) As String
Function ChangeIP (IP,NM,GW,MDNS,SDNS) '其中IP,NM,GW,MDNS,SDNS为字符串类型
'返回值说明:返回一个设置的中文说明.
Dim strComputer,objWMIService,colNetAdapters,strIPAddress,strSubnetMask
Dim strGateway,strGatewaymetric,strDNS,objNetAdapter,errEnable,errGateways,errDNS
strComputer = "."
Set objWMIService = GetObject( "winmgmts:\\" & strComputer & "\root\cimv2" )
Set colNetAdapters = objWMIService.ExecQuery( "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE ")
strIPAddress = Array(IP) 'ip地址
strSubnetMask = Array(NM) '子网掩码
strGateway = Array(GW) '网关
strDNS = Array(MDNS,SDNS) '主DNS各备DNS
strGatewaymetric = Array(1)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
ChangeIP = "设置成功 "
Else
If errEnable = 0 Then
ChangeIP = "IP地址和子网掩码设置成功, "
Else
ChangeIP = "IP地址或子网掩码设置失败, "
End If
If errGateways = 0 Then
ChangeIP = ChangeIP & "默认网关设置成功, "
Else
ChangeIP = ChangeIP & "默认网关设置失败, "
End If
If errDNS = 0 Then
ChangeIP = ChangeIP & "DNS设置成功 "
Else
ChangeIP = ChangeIP & "DNS设置失败 "
End If
End If
Next
End Function
热心网友
时间:2023-10-21 19:49
其实比较简单。。但问题是你需要先统计好每台机器的MAC地址,因为你既然需要自动修改,那么就需要一个判断依据。。这个依据就是MAC。。以前我在网吧工作的时候,那时候没有现在那种通过服务器来修改IP的功能,所以当GHOST完后每台修改IP和计算机名就是个苦累活。。然后自己统计每台的MAC,写了个通过MAC来修改计算机名称以及IP的批处理。你这个原理应该差不多。。
热心网友
时间:2023-10-21 19:49
自己慢慢修改吧,光写脚本的时间都够修改完了
热心网友
时间:2023-10-21 19:48
ChangeIP "192.168.1.2", "255.255.255.0", "192.168.1.1", "192.168.1.1", "192.168.2.1"
'Function ChangeIP (IP As String,NM As String,GW As String,MDNS As String,SDNS As String) As String
Function ChangeIP (IP,NM,GW,MDNS,SDNS) '其中IP,NM,GW,MDNS,SDNS为字符串类型
'返回值说明:返回一个设置的中文说明.
Dim strComputer,objWMIService,colNetAdapters,strIPAddress,strSubnetMask
Dim strGateway,strGatewaymetric,strDNS,objNetAdapter,errEnable,errGateways,errDNS
strComputer = "."
Set objWMIService = GetObject( "winmgmts:\\" & strComputer & "\root\cimv2" )
Set colNetAdapters = objWMIService.ExecQuery( "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE ")
strIPAddress = Array(IP) 'ip地址
strSubnetMask = Array(NM) '子网掩码
strGateway = Array(GW) '网关
strDNS = Array(MDNS,SDNS) '主DNS各备DNS
strGatewaymetric = Array(1)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
ChangeIP = "设置成功 "
Else
If errEnable = 0 Then
ChangeIP = "IP地址和子网掩码设置成功, "
Else
ChangeIP = "IP地址或子网掩码设置失败, "
End If
If errGateways = 0 Then
ChangeIP = ChangeIP & "默认网关设置成功, "
Else
ChangeIP = ChangeIP & "默认网关设置失败, "
End If
If errDNS = 0 Then
ChangeIP = ChangeIP & "DNS设置成功 "
Else
ChangeIP = ChangeIP & "DNS设置失败 "
End If
End If
Next
End Function
热心网友
时间:2023-10-21 19:49
其实比较简单。。但问题是你需要先统计好每台机器的MAC地址,因为你既然需要自动修改,那么就需要一个判断依据。。这个依据就是MAC。。以前我在网吧工作的时候,那时候没有现在那种通过服务器来修改IP的功能,所以当GHOST完后每台修改IP和计算机名就是个苦累活。。然后自己统计每台的MAC,写了个通过MAC来修改计算机名称以及IP的批处理。你这个原理应该差不多。。
热心网友
时间:2023-10-21 19:49
自己慢慢修改吧,光写脚本的时间都够修改完了