#
coding:utf-8 import socket def URL2IP(): for oneurl in urllist.readlines(): url=str(oneurl.strip())[7:] print(url) try: ip =socket.gethostbyname(url) print(ip) iplist.writelines(str(ip)+"\n") except: print("this URL 2 IP ERROR ") try: urllist=open("D:\urllist.txt","r") iplist=open("D:\iplist.txt","w") URL2IP() urllist.close() iplist.close() print("complete !") except: print("ERROR !")

先上代码。刚刚军训完回来,在军训期间想写一个项目,所以就写了个域名解析主要用了socket里的gethostbyname来解析urllist.txt里的域名

然后解析完成后在写入到iplist.txt中

 

>>>运行>>>>>>

python解析域名

 

 python解析域名

 

相关文章:

  • 2021-12-15
  • 2021-09-14
  • 2021-09-16
  • 2021-09-17
猜你喜欢
  • 2021-11-27
  • 2021-09-08
  • 2021-10-22
  • 2021-10-07
  • 2021-11-05
相关资源
相似解决方案