1、 使用接口的方式:
这种方式是相对稳定,而且提供的数据相对稳定,提供接口的地方很多,大家可以参照
http://www.hujuntao.com/api/the-ip-address-api-and-call-the-interface-method.html
不一一讲解,只讲解一下新浪提供的接口:
新浪接口地址:http://int.dpool.sina.com.cn/iplookup/iplookup.php
参数有两个:format和ip
1) IP:不传入ip值时默认为本机ip,也可以指定特定的ip地址;
2) format:返回给客户端的数据格式有js和json格式:
a、 返回js格式:
eg:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=115.29.28.108
返回结果:var remote_ip_info = {"ret":1,"start":"115.28.0.0","end":"115.29.255.255","country":"\u4e2d\u56fd","province":"\u5317\u4eac","city":"\u5317\u4eac","district":"","isp":"\u7535\u4fe1","type":"\u673a\u623f","desc":"\u4e2d\u56fd\u4e07\u7f51\u673a\u623f\u7535\u4fe1"};
返回的结果给一个js变量,变量值为json格式,可以自己将Unicode字符转码为中文:
var remote_ip_info = {"ret":1,"start":"115.28.0.0","end":"115.29.255.255","country":"中国","province":"北京","city":"北京","district":"","isp":"电信","type":"机房","desc":"中国万网机房电信"};
b、 返回json格式:
eg:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=115.29.28.108
返回结果:
{"ret":1,"start":"115.28.0.0","end":"115.29.255.255","country":"\u4e2d\u56fd","province":"\u5317\u4eac","city":"\u5317\u4eac","district":"","isp":"\u7535\u4fe1","type":"\u673a\u623f","desc":"\u4e2d\u56fd\u4e07\u7f51\u673a\u623f\u7535\u4fe1"}
返回的结果直接是一个json格式的字符串,可以自己将Unicode字符转码为中文:
{"ret":1,"start":"115.28.0.0","end":"115.29.255.255","country":"中国","province":"北京","city":"北京","district":"","isp":"电信","type":"机房","desc":"中国万网机房电信"}
代码示例:
<div> <asp:GridView ID="gvDetail" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" AutoGenerateColumns="false"> <AlternatingRowStyle BackColor="White" /> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> <Columns> <asp:TemplateField HeaderText="IP地址"> <ItemTemplate> <div style=" text-align:center"><%#Eval("IP")%></div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="国家"> <ItemTemplate> <div style=" text-align:center"><%#Eval("Country")%></div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="省会"> <ItemTemplate> <div style=" text-align:center"><%#Eval("Province")%></div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="城市"> <ItemTemplate> <div style=" text-align:center"><%#Eval("City")%></div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="地区"> <ItemTemplate> <div style=" text-align:center"><%#Eval("District")%></div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="运营商"> <ItemTemplate> <div style=" text-align:center"><%#Eval("Isp")%></div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="类型"> <ItemTemplate> <div style=" text-align:center"><%#Eval("Type")%></div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="描述"> <ItemTemplate> <div style=" text-align:center"><%#Eval("Desc")%></div> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div>
返回栏目页:http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索中国
, 北京
, 格式
, 万网
, 万网接口
, php获取本机IP地址
新浪api接口
ip地址获取地理位置、js获取当前地理位置、微信获取当前地理位置、java获取当前地理位置、h5 获取当前地理位置,以便于您获取更多的相关知识。