久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

基于python實(shí)現(xiàn)查詢ip地址來(lái)源

瀏覽:124日期:2022-07-23 14:31:37

從http://freeapi.ipip.net和http://ip-api.com/json/這兩個(gè)網(wǎng)站提供的免費(fèi)調(diào)用接口查詢IP地址歸屬地。

接口調(diào)用方法是在url后面直接加上IP地址。

url = ’http://freeapi.ipip.net/218.192.3.42’ #中文免費(fèi)url2 = ’http://ip-api.com/json/218.192.3.42’ #外國(guó)網(wǎng)站

ip.py:

import sysimport requestsdef main(argv): url = ’http://freeapi.ipip.net/’ #中文免費(fèi) url2 = ’http://ip-api.com/json/’ #外國(guó)網(wǎng)站 args = sys.argv[1] url=url+format(args) url2 = url2 + format(args) response = requests.get(url) response2 = requests.get(url2) str=response.text.replace(’'’,’’) #去掉雙引號(hào) str=str.replace(’[’,’’) #去掉方括號(hào) str=str.replace(’]’,’’) str=str.replace(’ ’,’’) str=str.split(',') #已逗號(hào)為分割符號(hào),分割字符串為數(shù)組 print('****************************************') print('您查詢的IP地址 %s 來(lái)源地是:'%args) print('國(guó)家:%s'%(str[0])) #訪問(wèn)數(shù)組里面的值 print('省份:%s'%(str[1])) print('城市:%s'%(str[2])) print('區(qū)域:%s'%(str[3])) str[4] = str[4].replace(’n’, ’’) #去掉回車符號(hào) print('運(yùn)營(yíng)商:%s'%(str[4])) print('數(shù)據(jù)來(lái)源<www.ipip.net免費(fèi)查詢接口>') print('****************************************') strpp={} #定義一個(gè)字典strpp strpp=response2.json() #把英文網(wǎng)站json接口返回值傳給字典strpp print('n')#下面就是直接從字典取值,顯示。 print('您查詢的IP地址 %s 來(lái)源地是:'%(strpp.get(’query’))) print('國(guó)家:%s'%(strpp.get(’country’))) print('城市:%s'%(strpp.get(’city’))) print('經(jīng)緯度坐標(biāo):%s,%s'%(strpp.get(’lat’),strpp.get(’lon’))) print('運(yùn)營(yíng)商編號(hào):%s'%(strpp.get(’as’))) print('ISP服務(wù)商:%s'%(strpp.get(’isp’))) print('數(shù)據(jù)來(lái)源<www.ip-api.com免費(fèi)查詢接口>') print('****************************************')if __name__ == '__main__': main(sys.argv)

運(yùn)行的方法是直接進(jìn)入該程序所在的工程文件夾中,

然后輸入cmd

基于python實(shí)現(xiàn)查詢ip地址來(lái)源

然后輸入python ip.py ip地址

基于python實(shí)現(xiàn)查詢ip地址來(lái)源

基于python實(shí)現(xiàn)查詢ip地址來(lái)源

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 哈尔滨市| 子洲县| 尉氏县| 益阳市| 平罗县| 上饶县| 柳河县| 元氏县| 自贡市| 青川县| 濮阳市| 上蔡县| 磐石市| 志丹县| 宁德市| 两当县| 资兴市| 陇西县| 望奎县| 石棉县| 武川县| 聊城市| 新龙县| 武胜县| 会同县| 济源市| 四会市| 绥中县| 襄垣县| 林西县| 富川| 略阳县| 咸宁市| 谷城县| 宜春市| 辰溪县| 环江| 中山市| 永济市| 宜昌市| 牟定县|