Network programming in python with examples
GETING A HOST NAME >>> import socket >>> host_name = socket.gethostname() >>> print ("Host name: %s" %host_name) >>> print ("IP address: %s",host_name) GETTING A HOST NAME WITH A FUNCTION DEFINITION import socket def print_machine_info(): host_name = socket.gethostname() ip_address = socket.gethostbyname(host_name) print ("Host name: " ,host_name) print ("IP address: " ,ip_address) if __name__ == '__main__': print_machine_info() The hostname is what you assigned to your computer when you configured your operating system. This output will be different on your machine depending on the system's host configuration. Here hostname indicates where the Python interpreter is currently executing. Retrieving a remote machine's IP address If you need to know the IP address of a remote machine, you can use a built-in library function, gethostbyname(). In this c...