Skip to content

Instantly share code, notes, and snippets.

@d0n601
Created October 15, 2016 03:34
Show Gist options
  • Save d0n601/b1457903fcaf9f784b760905291d53c1 to your computer and use it in GitHub Desktop.
Save d0n601/b1457903fcaf9f784b760905291d53c1 to your computer and use it in GitHub Desktop.
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