由域名获取该域名的ip地址,获取域名ip地址,[Python]代码im
由域名获取该域名的ip地址,获取域名ip地址,[Python]代码im
[Python]代码
import urllibimport httplibimport reimport urlparseimport jsondef ip(host_addr,format="dot"): ''' describe: function try to find the ip addr of the given host addr params: host_addr:the format like www.baidu.com or http://www.baidu.com format:the format of return value dot=>ip string like 123.121.121.21, num=>number format like 327382483 return :IP string list or number list when num specified ''' query_url='http://ip.chinaz.com/?' if host_addr.startswith("http"): req_url=urlparse.urlsplit(host_addr).netloc else: req_url=host_addr r=urllib.urlopen(query_url+"IP="+req_url) ipRex=r':\s+([\d\.]*)\s' try: if r !=None: context=r.read() rst=re.findall(ipRex,context) if rst!=None: if format=="num": rss=[] for rs in rst: sum=0 for f in enumerate(rs.split('.')): sum+=int(f[1])<<((3-f[0])*8) rss.append(str(sum)) del rst rst=rss return rst return None except : return None
相关内容
- 百度指定行业seo市场竞争度查询工具,seo市场竞争,[P
- 福彩3D号码预测,福彩3d预测,[Python]代码im
- 采用右递归的超简单八皇后解决,采用递归皇后,[Pyth
- 人人自动@所有好友,人人好友,[Python]代码#
- boost regex 获取 FTP 响应响应消息,boostregex,boost regex获
- Python爬取红黑联盟读书频道的图书,python读书频道,2.
- Learn Python By Practice — Utilities模块,pythonutilities,Utilit
- Google Python Class练习解答1-string1.py,python1-string1.py,stri
- Learn Python By Practice — 排序和元组,pythonpractice,排序和
- 用urllib按照百度音乐分类下载mp3,urllib百度音乐mp3,[P
评论关闭