首页 > 编程语言 > 详细

Python获取本机外网IP

时间:2015-08-04 22:24:13      阅读:363      评论:0      收藏:0      [点我收藏+]

1. 打开https://www.baidu.com/

2. 输入ip, 进行搜索, 获取url

http://cn.bing.com/search?q=ip&go=%E6%8F%90%E4%BA%A4&qs=n&form=QBLH&pq=ip&sc=8-2&sp=-1&sk=&cvid=14b93b305cdc4183875411c3d9edf938

3. 查找url返回结果

   技术分享

   编写python匹配正则表达式

4. Python完整代码

  

 1 # -*- coding: utf-8 -*-
 2 import urllib2
 3 import re
 4 __author__ = 10
 5 url = "http://cn.bing.com/search?q=ip&go=%E6%8F%90%E4%BA%A4&qs=n&form=QBLH&pq=ip&sc=8-2&sp=-1&sk=&cvid=14b93b305cdc4183875411c3d9edf938"
 6 html = urllib2.urlopen(url).read()
 7 #print html
 8 html_re = re.compile(r本机 ip: (.+?) 上海市 联通,re.DOTALL)
 9 for x in html_re.findall(html):
10     print "Public IP:" + x

 

   

5. 运行结果

    技术分享

Python获取本机外网IP

原文:http://www.cnblogs.com/anit/p/4702070.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!