天天看點

如何在網頁讀取使用者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("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>

  顯示:

如何在網頁讀取使用者IP,作業系統版本等資料demo

最新内容請見作者的github頁:http://qaseven.github.io/

繼續閱讀