Learning Python Network Programming

(Sean Pound) #1
Chapter 1

IP addresses perform two main functions. They are as follows:



  • They uniquely address each device that is connected to a network

  • They help the traffic to be routed between networks


You may have noticed that the network-connected devices that you use have IP
addresses assigned to them. Each IP address that is assigned to a network device
is unique and no two devices can share an IP address.


Network interfaces


You can find out what IP addresses have been assigned to your computer by running
ip addr (or ipconfig /all on Windows) on a terminal. In Chapter 6, IP and DNS,
we'll see how to do this when using Python.


If we run one of these commands, then we can see that the IP addresses are assigned
to our device's network interfaces. On Linux, these will have names, such as eth0;
on Windows these will have phrases, such as Ethernet adapter Local Area
Connection.


You will get the following output when you run the ip addr command on Linux:


$ ip addr


1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN


link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00


inet 127.0.0.1/8 scope host lo


valid_lft forever preferred_lft forever


2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000


link/ether b8:27:eb:5d:7f:ae brd ff:ff:ff:ff:ff:ff


inet 192.168.0.4/24 brd 192.168.0.255 scope global eth0


valid_lft forever preferred_lft forever


In the preceding example, the IP addresses for the interfaces appear after the
word inet.


An interface is a device's physical connection to its network media. It could be
a network card that connects to a network cable, or a radio that uses a specific
wireless technology. A desktop computer may only have a single interface for a
network cable, whereas a Smartphone is likely to have at least two interfaces, one for
connecting to Wi-Fi networks and one for connecting to mobile networks that use 4G
or other technologies.

Free download pdf