[JavaScript] 纯文本查看 复制代码 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JavaScript获取客户端IP</title>
<script type="text/javascript" language="javascript">
<!--
function GetLocalIPAddress()
{
var obj = null;
var rslt = "";
try
{
obj = new ActiveXObject("rcbdyctl.Setting");
rslt = obj.GetIPAddress;
obj = null;
}
catch(e)
{
//异常发生
}
return rslt;
}
function getMac(){
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True");
var e = new Enumerator (properties);
{
var p = e.item();
var mac = p.MACAddress;
return mac
}
}
//-->
function init () {
var ip = GetLocalIPAddress();
var mac = getMac();
fm.clientIP.value = ip;
fm.clientMAC.value = mac;
}
</script>
</head>
<body onload="init();">
<form name = 'fm'>
通过JavaScript获取的IP信息:<input type ='text' name = 'clientIP'><br>
通过JavaScript获取的MAC信息:<input type='text'name = 'clientMAC'>
通过JSP获取的IP信息:<%= request.getRemoteAddr() %>
</form>
</body>
</html> |