Created
October 15, 2016 03:34
-
-
Save d0n601/b1457903fcaf9f784b760905291d53c1 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
import urllib3 | |
import signal | |
class TimeoutException(Exception): | |
pass | |
def timeout_handler(signum, frame): | |
raise TimeoutException | |
def main(): | |
signal.signal(signal.SIGALRM, timeout_handler) # I control the timeout | |
block = "138.68.30." | |
http = urllib3.PoolManager() | |
for i in range(5, 200): | |
signal.alarm(3) | |
try: | |
try: | |
ip = block + str(i) | |
r = http.request('GET', ip) | |
if r.status == 200: | |
print('live site found ' + str(ip)) | |
except: | |
print('nothing found on ' + str(ip)) | |
except TimeoutException: | |
print('ip timed out ' + str(ip)) | |
continue # continue the for loop if function A takes more than 5 second | |
else: | |
signal.alarm(0) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment