Learning Python Network Programming

(Sean Pound) #1

Network Programming and Python


So, how does this help in routing? When a network device generates network traffic
that needs to be sent across a network, it first compares the destination's IP address
with its own network prefix. If the destination IP address has the same network
prefix as that of the sending device, then the sending device will recognise that the
destination device is on the same network and, therefore, it can then send the traffic
directly to it. If the network prefixes differ, then it will send the message to its default
gateway, which will forward it on towards the receiving device.


When a router receives traffic that has to be forwarded, it first checks whether
the destination IP address matches the network prefix of any of the networks that
it's connected to. If that is the case, then it will send the message directly to the
destination device on that network. If not, it will consult its routing table. If it finds a
matching rule, then it sends the message to the router that it found listed, and if there
are no explicit rules defined, then it will send the traffic to its own default gateway.


When we create a network with a given network prefix, in the 32-bits of the IP address,
the digits to the right of the network prefix are available for assignment to the network
devices. We can calculate the number of the available addresses by raising 2 to the
power of the number of available bits. For example, in a /28 network prefix, we
have 4 bits left, which means that 16 addresses are available. In reality, we are able to
assign fewer addresses, since two of the addresses in the calculated range are always
reserved. These are: the first address in the range, which is called the network address
and the last address in the range, which is called the broadcast address.


This range of addresses, which is identified by its network prefix, is called a
subnet. Subnets are the basic unit of assignment when IANA, an RIR or an ISP
allocates IP address blocks to organizations. Organizations assign subnets to
their various networks.


Organizations can further partition their addresses into subnets simply by
employing a longer network prefix than the one they had been assigned. They
might do this either to make more efficient use of their addresses or to create a
hierarchy of networks, which can be delegated across the organization.


DNS


We've discussed connecting to network devices by using IP addresses. However,
unless you work with networks or in systems administration, it is unlikely that you
will get to see an IP address very often, even though many of us use the Internet
every day. When we browse the web or send an e-mail, we usually connect to servers
using host names or domain names. These must somehow map to the servers' IP
addresses. But how is this done?

Free download pdf