如何在網頁讀取用戶IP,操作系統版本等數據demo
我們瀏覽網頁的時候,會不經意間看到,有些地方(如個人的簽名檔)顯示出了個人的IP,操作系統等數據.借助第三方API和請求報頭useragent是很容易實現的.
<html> <head> <title>Sherry</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://counter.sina.com.cn/ip/" charset="gb2312"></script> <script> document.writeln("IP地址:"+ILData[0]+"<br />"); //輸出接口數據中的IP地址 document.writeln("地址類型:"+ILData[1]+"<br />"); //輸出接口數據中的IP地址的類型 document.writeln("地址類型:"+ILData[2]+"<br />"); //輸出接口數據中的IP地址的省市 document.writeln("地址類型:"+ILData[3]+"<br />"); //輸出接口數據中的IP地址的 document.writeln("地址類型:"+ILData[4]+"<br />"); //輸出接口數據中的IP地址的運營商 //document.write(navigator.userAgent + "<br>"); document.write("您的操作系統版本為:"); if(navigator.userAgent.indexOf("Windows NT 6.2") > 0){ document.write("Windows 8"); } else if(navigator.userAgent.indexOf("Windows NT 6.1") > 0){ document.write("Windows 7"); } else if(navigator.userAgent.indexOf("Windows NT 6.0") > 0){ document.write("Windows Vista"); } else if(navigator.userAgent.indexOf("Windows NT 5.2") > 0){ document.write("Windows 2003"); } else if(navigator.userAgent.indexOf("Windows NT 5.1") > 0){ document.write("Windows xp"); } else if(navigator.userAgent.indexOf("Windows NT 5.0") > 0){ document.write("Windows 2000"); } </script> </head> <body> </body> </html> |
顯示: