最新文章:

您的位置: 富录-前端开发|web技术博客 > JavaScript > JavaScript获取IP地址

JavaScript获取IP地址

发布时间:2017年07月10日 评论数:抢沙发阅读数: 10287

    JavaScript不能直接获取用户的ip地址,只能通过调用API的方法来获得。

    可以通过以下几个地址获得:

    1616.net:http://chaxun.1616.net/s.php?type=ip&output=json

    function getadress(){         
    		$.ajax({  
    			url: "http://chaxun.1616.net/s.php?type=ip&output=json", 
    			dataType:"jsonp",  
    			success: function(data){   
    				console.log(data.Ip+"-"+data.Isp)               
    			},
    			error: function(data) {
    			}  
    		});  
    }  
    getadress()

     

    百度:http://api.map.baidu.com/location/ip?ak=要到开放平台获取ak&coor=bd09ll

    function getadress(){         
    		$.ajax({  
    			// 百度需要获取ak 
    			// url: "http://api.map.baidu.com/location/ip?ak=先获取Ak&coor=bd09ll",  
    			dataType:"jsonp",  
    			success: function(data){   
    				console.log(data)              
    			},
    			error: function(data) {
    			}  
    		});  
    }  
    getadress()


     搜狐:http://pv.sohu.com/cityjson
          搜狐:http://pv.sohu.com/cityjson?ie=utf-8可设置编码

    <script charset="utf-8" src="http://pv.sohu.com/cityjson" type="text/javascript"></script>
    <script>
        console.log(returnCitySN["cip"],returnCitySN["cname"])
    </script>

         

    coding123:http://www.coding123.net/getip.ashx?js=1

    <script type="text/javascript" src="http://www.coding123.net/getip.ashx?js=1"></script>
    <script>
        console.log(ip)
    </script>

         

    新浪:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=[ip地址]

    <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
    <script type="text/javascript">
         console.log(remote_ip_info["country"]+','+remote_ip_info["province"]+"省"+','+remote_ip_info["city"]+"市")//中国,江苏省,南京市
    </script>


二维码加载中...
本文作者:DGF      文章标题: JavaScript获取IP地址
本文地址: https://arbays.com/post-27.html     本文已被百度收录!
版权声明:若无注明,本文皆为“富录-前端开发|web技术博客”原创,转载请保留文章出处。
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论