def statusCheck(URL,PORT):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((URL,PORT))
return result
Here URL = "http://127.0.0.1"
When I am calling statusCheck function with below parameter,
I got error.
BASE_URL = "http://127.0.0.1"
PORT = 7000
res = statusCheck(BASE_URL,PORT)
print (res)
Error:
Traceback (most recent call last):
File "test.py", line 15, in <module>
res = statusCheck(BASE_URL,PORT)
File "test.py", line 12, in statusCheck
result = sock.connect_ex((URL,PORT))
File "/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -2] Name or service not known
When I use URL = "127.0.0.1". It work fine.
So my question is how I can get ipv4 address from a url which contains http://