I have been trying to get the ipaddress of the person who logged into the machine using the below code but I get a error.
>>> import socket
>>> socket.gethostbyname_ex(socket.gethostname())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
The same code works in other linux box. Not sure I fix it.
Error has occurred just because of not setting up hostname properly. Set the hostname at three different places, which are in -
- /etc/hostname
- /etc/hosts
- run command $ hostname
then logout and login again. You are done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With