在一些嵌入式设备,在使用了4G拨号以后,需要知道自己设备的对外IP,采用以下几种方法可以轻松获得。
方法一:
1) get http://ipinfo.io/ip
response: {"clientIP":"124.129.11.204"}
or GET http://ifconfig.me/ip
2) 获取我的城市
GET http://ip.taobao.com/outGetIpInfo?ip=124.129.11.204&accessKey=alibaba-inc
RESP:
{"data":{"area":"","country":"中国","isp_id":"100026","queryIp":"124.129.11.204","city":"青岛","ip":"124.129.11.204","isp":"联通","county":"","region_id":"370000","area_id":"","county_id":null,"region":"山东","country_id":"CN","city_id":"370200"},"msg":"query success","code":0}
方法二:搜狐IP地位
GET http://pv.sohu.com/cityjson?ie=utf-8
RESP:
var returnCitySN = {"cip": "124.129.11.204", "cid": "370200", "cname": "山东省青岛市"};
方法三:高德地图IP定位,设备需要支持HTTPS
GET https://lbs.amap.com/api/webservice/guide/api/ipconfig/