(Oct-21-2016, 05:33 PM)Blue Dog Wrote: what is a remote_ip = '111.111.111, that only have 3 set of numbers, most ip have 4 set of numbers 111.111.111.111?It could have been any number,i was just showing what was wrong with this line:
print ('Ip address of ') + host + ' is ' + remote_ip # ) wrong placementThe correct and best way:
print('Ip address of {} is {}'.format(host, remote_ip))Have you not look into now how interactive interpreter work?
You can try this code:
import socket import sys try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) except socket.error as msg: print('Failed to create socket. Error code: {}'.format(str(msg))) sys.exit() print('Socket Created') host = 'www.google.com' port = 80 try: remote_ip = socket.gethostbyname(host) except socket.gaierror: print('Hostname could not be resolved. Exiting') sys.exit() print('Ip address of {} is {}'.format(host, remote_ip)) s.connect((remote_ip , port)) print('Socket Connected to {} on ip {}'.format(host, remote_ip))