Hello everyone, In last three tutorials we learn about the socket declaration, server socket and client socket configuration. In coming tutorials I will share examples like web server, client server chat program.Let’s cover all the basic topics first before examples.

In this tutorial we will cover Address look up function,

1) gethostbyname(hostname): It translate the host name to a IPV4 format. The IPV4 address is returned as a string such as 10.10.10.1. It does not support IPV6.

2) gethostbyname_ex(hostname): Translate the host name to IPv4 address format, extended interface. Return a triple (hostname, alias list, IP address list). It also does not support IPV6.

3) gethostname(): Return a string containing the host name of the machine where the python interpreter is currently executing. If you want to know the current machine IP address, you have to use gethostbyname(gethostname()).

4) getfqdn(name): Return a fully qualified domain name for name. If name is omitted or empty, it is interpreted as localhost.

5) gethostbyaddress(IP address): Return a triple (hostname, alias list, IP address list). It support both IPV4 and IPV6.

6) getnameinfo(sockaddr, flags): Translate a sockaddr into a 2 tuple (host, port) depending on the setting of flags. The result contain a fqdn or numeric address representation of host.

7) socket.getprotobyname(protocol name): Translate an internal protocol name to a constant suitable for passing as the third argument to the socket function. This is usually needed for a socket opened in a raw mode, for normal socket mode the correct protocol is chosen automatically.

8) getservbyname(service name [, protocol name]: Translate an internal service name and protocol name to a port number for that service. The optional protocol name, if given should be tcp or udp otherwise any protocol will match.

9) getservbyport(port [, protocol name]: Translate an internal port number and protocol name to a service name for that service.

These are some function. 7, 8 and 9 are not useful to us but other are really important and very useful we will cover them all in the example.

Follow us on Facebook.

Thanks
Abhishek.

Leave a comment