from socket import socket, SOCK_DGRAM, AF_INET def localip(): s = socket(AF_INET, SOCK_DGRAM) s.connect(('114.114.114.114', 0)) return s.getsockname()[0] if __name__ == "__main__": print localip()