Created
August 25, 2012 10:37
-
-
Save ninehills/3463463 to your computer and use it in GitHub Desktop.
check_google_ip
This file contains 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 | |
# coding:utf-8 | |
import sys | |
import os | |
import re | |
import gevent | |
import gevent.monkey | |
import gevent.timeout | |
gevent.monkey.patch_all() | |
import urllib2 | |
def check_ip(ip): | |
try: | |
with gevent.timeout.Timeout(5): | |
response = urllib2.urlopen('http://%s/' % ip) | |
text = response.read() | |
if 'google' in text: | |
print ip | |
except gevent.timeout.Timeout as e: | |
pass | |
except Exception as e: | |
pass | |
def main(): | |
greenlets = [gevent.spawn(check_ip, '203.208.46.%d' % i) for i in xrange(1, 256)] | |
gevent.joinall(greenlets) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment