import os, socket def public_ip(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('114.114.114.114', 80)) ip = s.getsockname()[0] finally: s.close() print ip return ip if __name__ == "__main__": public_ip()
import os, socket def public_ip(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('114.114.114.114', 80)) ip = s.getsockname()[0] finally: s.close() print ip return ip if __name__ == "__main__": public_ip()