Skip to content

Instantly share code, notes, and snippets.

@kurosuke
Created November 20, 2013 13:04
Show Gist options
  • Save kurosuke/7562800 to your computer and use it in GitHub Desktop.
Save kurosuke/7562800 to your computer and use it in GitHub Desktop.
hostname convert to host ip. try mypc/mypc.local/mypc.localdomain
#!/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