Tuesday, July 7, 2009

How To Get IP Address


<html>
<head>
<title>WMI Scripting HTML</title>
<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">
document.getElementById('divMACAddr').innerHTML='Machine Number :'+unescape(vMACAddr);
document.getElementById('divIPAddr').innerHTML='IP Address :'+unescape(vIPAddr);
document.getElementById('divDNSName').innerHTML='DNS Name '+unescape(vDNSName);
</script>

<script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true)
{
if(objObject.MACAddress != null && objObject.MACAddress != "undefined")
vMACAddr = objObject.MACAddress;

if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined")
vIPAddr = objObject.IPAddress(0);

if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined")
vDNSName = objObject.DNSHostName;

}
</script>
</head>
<body>
<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" VIEWASTEXT></object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo"></object>

<script LANGUAGE="JScript">
var service = locator.ConnectServer();
var vMACAddr ;
var vIPAddr ;
var vDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
</script>

<form method="POST" action="NICPost.asp" id="formfoo" name="formbar">
<div id="divMACAddr"></div>
<div id="divIPAddr"></div>
<div id="divDNSName"></div>
</form>
</body>
</html>

Note:ActiveX to be Enabled, It Will Prompt to Get User To allow or not allow(IE )


No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.