Created
September 14, 2017 12:56
-
-
Save Cnly/0eeccbbeb68a147dbce4381501e78148 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# Partial original code came from https://www.oschina.net/code/snippet_20912_46623 | |
import urllib2 | |
import re | |
import sys | |
import traceback | |
if len(sys.argv) < 2: | |
print 'At least provide 1 IP' | |
exit(1) | |
ips = sys.argv[1:] | |
for i, ipaddr in enumerate(ips): | |
try: | |
print 'IP:', ipaddr | |
url = "http://www.ip138.com/ips138.asp?ip=%s&action=2" % ipaddr | |
r = urllib2.Request(url, headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36'}) | |
u = urllib2.urlopen(r) | |
s = u.read().decode('gbk') | |
result = re.findall(r'(<li>.*?</li>)',s) | |
for x in result: | |
print ' ' + x[4:-5] | |
if i != len(ips) - 1: | |
print '---------------' | |
except KeyboardInterrupt: | |
exit(1) | |
except: | |
print "Err: %s" % ipaddr | |
traceback.print_exc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment