首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

python3 编写的目标网站域名IP查询,附源码

python 3 编写的查询ip小程序。

PyCharm 环境编写的,还没有测试过。

使用记事本编写,速度快。保存成ipp.py文件名和UTF-8编码格式。

保存路径 D:\py\ipp.py 运行结果如下。

查看qq.com结果。

查看百度baidu.com

查看微博weibo.com,原来这个微博时ipV6

我们这里连接到微博的物理服务器放在MA

查询一个IP 360杀毒软件的地址。

编辑思路是把查询到的信息以可读的方式打印到屏幕上面:

程序员读的和普通人读的对比

直接输出结果像乱码#print(dict),上图是源码输出和可读输出对比

API入口requests.get()

web = requests.get('http://ip-api.com/json/'+ ip)

把得到的信息转换成字典格式:

dict = ast.literal_eval(web.text)

定义一个函数放打印格式,加中文翻译

dict.get()是从乱码里面拿各个数据的语句

最后是保存成为文本,备份使用。

以下是源代码:

import requests

import ast

#设置字体颜色

print("\033[1;32;40m \n")

print('输入要目标地址 网站名称 或者回车查询本机')

ip = input("目标地址:")

web = requests.get('http://ip-api.com/json/'+ ip)

dict = ast.literal_eval(web.text)

#print(dict)

#定义一个output函数,然后在屏幕打印出查询信息

def output():

print("目标地址: %s" % dict.get('query'))

print("自治系统: %s" % dict.get('as'))

print("所在城市: %s" % dict.get('city'))

print("目标国家: %s" % dict.get('country'))

print("国家简称: %s" % dict.get('countryCode'))

print("组织单位: %s" % dict.get('org'))

print("网络供应: %s" % dict.get('isp'))

print("区域名称: %s" % dict.get('regionName'))

print("区域简称: %s" % dict.get('region'))

print("当前状态: %s" % dict.get('status'))

print("目的时区: %s" % dict.get('timezone'))

print("邮编编码: %s" % dict.get('zip'))

print("坐标经度: %s" % dict.get('lat'))

print("坐标纬度: %s" % dict.get('lon'))

output()

#保存信息

dict = str(dict)

f = open("../ip.doc", "a")

f.write(dict)

f.close()

#返回字体颜色黑底白字

print("\033[1;37;40m \n")

运行环境windows python3.7.2

需要安装requests 模块

方法是命令行C:\> pip install requests

下载python 3

百度云下载:

https://pan.baidu.com/s/1zOuq4JHQwX3S1yIH1Q6DHQ

官方网站下载:

windows

https://www.python.org/ftp/python/3.7.2/python-3.7.2.exe

MacOS

https://www.python.org/ftp/python/3.7.2/python-3.7.2-macosx10.9.pkg

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20190202G08C9Y00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券