天天看点

如何在网页读取用户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/

继续阅读