根据chewinggum 说的,我试着写了下代码,还可以,但是有安全警告,这应和IE设置有关吧!
我这里没有IIS环境,没有做提交等处理。
<html>
<script language=vbscript>
function getIP()
strComputer = "."
set objlocator=createobject("wbemscripting.swbemlocator")
set wbemServices=objlocator.connectserver(strComputer,"root/cimv2")
Set wbemObjectSet = wbemServices.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE' ")
For Each wbemobject In wbemObjectSet
MsgBox "IP: " & wbemobject.ipaddress(0) & vbCrLf & _
"Mac:" & wbemobject.macaddress(0)
Next
end function
</script>
<body onload=getIP>
<form action=... method=get>
...
</form>
</body>
</html>
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
获得了本地IP