如果是我,我就会用VC写一个最简单的控件,获得一下本地的IP,然后传给JS代码,就可以用了哇
在vc里面的代码是
// 获得本机主机名称和IP地址
LPCTSTR CRealtimeServerDlg::GetLocalIPAddress()
{
        WORD wVersionRequested;
        WSADATA wsaData;
        char name[255];
        CString ip;
        PHOSTENT hostinfo;
        wVersionRequested = MAKEWORD( 2, 0 );        if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
        {              if( gethostname ( name, sizeof(name)) == 0)
              {
                    if((hostinfo = gethostbyname(name)) != NULL)
                    {
                          ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
                    }
              }
            
              WSACleanup( );
        }
return ip;
}希望有所帮助,其他方法,好像通过调用dos命令写临时文件的方法也可以获得,具体没有弄过

解决方案 »

  1.   

    tks!
    一个不错的方法,可现在用户总是把安全设置蛮高。还要谢谢你!
      

  2.   

    1.htm
    ------------------------------------
    function getClientIP () {
     var url = "server.asp"
     try
     {
      XmlHttp = new ActiveXObject("MSXML2.XMLHTTP")
     }
     catch(e)
     {
      XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     XmlDoc = new ActiveXObject("MSXML.DOMDocument"); XmlHttp.Open( "POST", url, false );
     XmlHttp.setRequestHeader( "Content-Type","text/XML" );
     XmlHttp.Send();
     if (XmlHttp.status != 200 || XmlHttp.responseXML.xml == "")
     {
      if (XmlHttp.status == 404) {
        alert("Server not found:" + url)
      }else {
        alert("Error found!")
      }
      return
     }
     XmlDoc.loadXML(XmlHttp.responseXML.xml);
     clientIP = XmlDoc.documentElement.selectSingleNode('//clientTP').text
     return clientIP
    }
    server.asp
    ------------------------------
    <script language=JScript runat=server>
     Response.ContentType = "text/xml" 
     Response.Write('<?xml version="1.0"?>')
     Response.Write('<root>')
     Response.Write('<clientIP>' + Request.ServerVariables('REMOTE_ADDR') + '</clientIP>') 
     Response.Write('</root>')
    </script>
      

  3.   

    to jonescheng
    当然有办法..... 执行DOS命令 临时存 不就可以了?呵呵 办法多的是 ,看你想不想!!!
      

  4.   

    代码如下:
        <%
    strMac=""
    strIP = Request.ServerVariables("REMOTE_ADDR")
        Set net = Server.CreateObject("wscript.network")
        Set sh = Server.CreateObject("wscript.shell")
        sh.run "%comspec% /c nbtstat -A " & strIP & " > c:\" & strIP & ".txt",0,true
        Set sh = nothing
        Set fso = createobject("scripting.filesystemobject")
        Set ts = fso.opentextfile("c:\" & strIP & ".txt")
        macaddress = null
        Do While Not ts.AtEndOfStream
        data = ucase(trim(ts.readline))
         if instr(data,"-------") Then
    data = ucase(trim(ts.readline))
    strHostname=trim(split(data,"<")(0))
    End if

    If instr(data,"MAC ADDRESS") Then
        macaddress = trim(split(data,"=")(1))
        Exit Do
        End If
        loop
        ts.close
        Set ts = nothing
        fso.deletefile "c:\" & strIP & ".txt"
        Set fso = nothing
    strMac = macaddress
    strMac=Replace(strMac,"-",":")
        %>
    IPMAC --->&nbsp;&nbsp;&nbsp;<%=strMac%>
      

  5.   

    用javascript获得的ip地址好象都只是本地内网的ip啊
    比如172.18.***或者169.254.***什么的
    不能获得在外网中看到的实际的ip地址啊