Last active
August 29, 2015 14:04
-
-
Save winny-/a34576a40f4918812d8d to your computer and use it in GitHub Desktop.
ipv4 only
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 | |
import socket | |
import sys | |
def main(host): | |
exit_code = 0 | |
try: | |
# This is a work-around for socket.gethostbyname() causing KeyboardInterrupt to be uncatchable. | |
# From: https://mail.python.org/pipermail/python-bugs-list/2007-July/039118.html | |
try: | |
address = socket.gethostbyname(host) | |
except KeyboardInterrupt: | |
raise | |
print(address) | |
except (socket.gaierror, KeyboardInterrupt): | |
exit_code = 1 | |
sys.exit(exit_code) | |
if __name__ == '__main__': | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment