Created
November 20, 2013 13:04
-
-
Save kurosuke/7562800 to your computer and use it in GitHub Desktop.
hostname convert to host ip. try mypc/mypc.local/mypc.localdomain
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/python | |
# -*- coding: utf-8 -*- | |
import socket | |
import sys | |
def hostip(hostname): | |
try: | |
print socket.gethostbyname(hostname) | |
except: | |
print "0.0.0.0" | |
if __name__ == '__main__': | |
if(len(sys.argv) != 2): | |
print "Usage: hostip.py hostname" | |
sys.exit() | |
hostname = sys.argv[1] | |
hostip(hostname) | |
# vi:set ts=4 sw=4 sts=4 ft=python et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment