+ All Categories
Home > Documents > IP address Subnetting Ping command in detail Sub · PDF fileIP address Subnetting Ping...

IP address Subnetting Ping command in detail Sub · PDF fileIP address Subnetting Ping...

Date post: 07-Feb-2018
Category:
Upload: buitu
View: 224 times
Download: 0 times
Share this document with a friend
47
Transcript
Page 1: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python
Page 2: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

IP address

Subnetting

Ping command in detail

Threads in Python

Sub process in Python

Page 3: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

3

IPv4 Addressing- Introduction

An IP address is a 32-bit address that uniquely and universally defines the connection of a host or a router to the Internet.

IP addresses are unique.

Page 4: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

4

An IP address is a 32-bit address.

Note:

Page 5: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

5

The IP addresses are unique.

Note:

Page 6: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

6

The address space of IPv4 is232 or 4,294,967,296.

Note:

Page 7: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

7

Dotted-decimal and Binary equivalent notation

Page 8: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

8

Change the following IP addresses from binary notation to dotted-decimal notation.

a. 10000001 00001011 00001011 11101111b. 11000001 10000011 00011011 11111111c. 11100111 11011011 10001011 01101111d. 11111001 10011011 11111011 00001111

Example 1

SolutionWe replace each group of 8 bits with its equivalent decimal numberand add dots for separation:

a. 129.11.11.239 b. 193.131.27.255c. 231.219.139.111 d. 249.155.251.15

Page 9: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 9

Change the following IP addresses from dotted-decimal notation tobinary notation.

a. 111.56.45.78 b. 221.34.7.82c. 241.8.56.12 d. 75.45.34.78

Example 2

SolutionWe replace each decimal number with its binary equivalent:

a. 01101111 00111000 00101101 01001110b. 11011101 00100010 00000111 01010010c. 11110001 00001000 00111000 00001100d. 01001011 00101101 00100010 01001110

Page 10: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python
Page 11: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite11

Finding the class in binary notation

Page 12: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 12

Find the class of each address:

a. 00000001 00001011 00001011 11101111b. 11000001 10000011 00011011 11111111c. 10100111 11011011 10001011 01101111d. 11110011 10011011 11111011 00001111

Example

Solution

a. The first bit is 0. This is a class A address.b. The first 2 bits are 1; the third bit is 0. This is a class C address.c. The first bit is 0; the second bit is 1. This is a class B address.d. The first 4 bits are 1s. This is a class E address..

Page 13: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite13

Finding the class in decimal notation

Page 14: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 14

Find the class of each address:

a. 227.12.14.87 b.193.14.56.22 c.14.23.120.8d. 252.5.15.111e.134.11.78.56

Example

Solutiona. The first byte is 227 (between 224 and 239); the class is D.b. The first byte is 193 (between 192 and 223); the class is C.c. The first byte is 14 (between 0 and 127); the class is A.d. The first byte is 252 (between 240 and 255); the class is E.e. The first byte is 134 (between 128 and 191); the class is B.

Page 15: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite15

Netid and hostid

Page 16: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 16

Given the network address 17.0.0.0, find the class,the block, and the range of the addresses.

Example

SolutionThe class is A because the first byte is between 0 and 127.

The block has a netid of 17.

The addresses range from 17.0.0.0 to 17.255.255.255.

Page 17: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 17

Given the network address 132.21.0.0, find the class,the block, and the range of the addresses.

Example

Solution

The class is B because the first byte is between 128 and 191.

The block has a netid of 132.21.

The addresses range from 132.21.0.0 to 132.21.255.255.

Page 18: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 18

Given the network address 220.34.76.0, find theclass, the block, and the range of the addresses.

Example

SolutionThe class is C because the first byte is between 192 and 223.

The block has a netid of 220.34.76.

The addresses range from 220.34.76.0 to 220.34.76.255.

Page 19: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 19

Masking concept

Page 20: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 20

AND operation

Page 21: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 21

Page 22: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 22

The network address is the beginning address of each block. It

can be found by applying the default mask to any of the addresses in the block (including itself). It retains the

netid of the block and sets the hostid to zero.

Note:

Page 23: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 23

Given the address 23.56.7.91, find the beginningaddress (network address).

Example

SolutionThe default mask is 255.0.0.0,

which means that only the first byte is preserved

and the other 3 bytes are set to 0s.

The network address is 23.0.0.0.

Page 24: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 24

Given the address 132.6.17.85, find the beginningaddress (network address).

Example

SolutionThe default mask is 255.255.0.0,

which means that the first 2 bytes are preserved

and the other 2 bytes are set to 0s.

The network address is 132.6.0.0.

Page 25: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 25

Given the address 201.180.56.5, find thebeginning address (network address).

Example

SolutionThe default mask is 255.255.255.0, whichmeans that the first 3 bytes are preservedand the last byte is set to 0. The networkaddress is 201.180.56.0.

Page 26: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

.

Page 27: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 27

IPv4 Addressing- Subnetting

The problems associated with classful addressing is

that the network addresses available for assignment

to organizations are close to depletion.

This is coupled with the ever-increasing demand for

addresses from organizations that want connection

to the Internet.

In this section we briefly discuss two solutions:

subnetting and supernetting.

Page 28: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 28

IP addresses are designed with two levels of hierarchy.

Note:

Page 29: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 29

A network with two levels of hierarchy (not subnetted)

Page 30: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 30

Addresses in a network with and without subnetting

Page 31: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 31

Default mask and subnet mask

Page 32: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 32

Comparison of a default mask and a subnet mask

Page 33: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 33

What is the subnetwork address if the destination address is200.45.34.56 and the subnet mask is 255.255.240.0?

Example

SolutionWe apply the AND operation on the address and the subnet mask.

Address ➡ 11001000 00101101 00100010 00111000

Subnet Mask ➡ 11111111 11111111 11110000 00000000

Subnetwork Address ➡ 11001000 00101101 00100000 00000000.

Page 34: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 34

Example 1: A service provider has given you the Class C networkrange 209.50.1.0. Your company must break the network into 20separate subnets.

Style -1 Subnetting when given a required number of networks

SolutionStep 1) Determine the number of subnets and convert to binary -In this example, the binary representation of 20 = 00010100.

Step 2) Reserve required bits in subnet mask and find incremental value - The binary value of 20 subnets tells us that we need at least 5 network bits to satisfy this requirement

Page 35: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 35

- Our original subnet mask is 255.255.255.0 (Class C subnet) - The full binary representation of the subnet mask is as follows: 255.255.255.0 = 11111111.11111111.11111111.00000000

- We must “convert” 5 of the client bits (0) to network bits (1) in order to satisfy the requirements: New Mask = 11111111.11111111.11111111.11111000

-If we convert the mask back to decimal, we now have the subnet mask that will be used on all the new networks – 255.255.255.248 –

Example 1 continued

Page 36: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 36

New subnet mask 255.255.255.248

Our increment bit is the last possible network bit, converted back to a binary number:

New Mask = 11111111.11111111.11111111.1111(1)000 –

bit with the parenthesis is your increment bit.

If you convert this bit to a decimal number, it becomes the number “8” that is every subnet is having 8 addresses allotted to it (from 0 to 7, then 8 to 15 etc)

Example 1 continued

Page 37: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

TCP/IP Protocol Suite 37

Step 3) Use increment to find network ranges

You can now fill in your end ranges, which is the last possible IP address before you start the next range 209.50.1.0 – 209.50.1.7 209.50.1.8 – 209.50.1.15209.50.1.16 – 209.50.1.23 …etc

You can then assign these ranges to your networks!

Remember the first and last address from each range (network / broadcast IP) are unusable

Example 1 continued

Page 38: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

ping - may be used to test basic 2-way connectivity

Syntax Ping [-c count] [-i wait] [-l preload] [-p pattern]

[-s packetsize] hostname/IPAddress

DESCRIPTION Ping uses the ICMP protocol‟s mandatory

ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams („„pings‟‟) have an IP and ICMP header, followed by a “struct timeval” and then an arbitrary number of „„pad‟‟ bytes used to fill out the packet.

Page 39: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

ping 10.1.32.124

response from 10.1.32.124

Reply from 74.125.224.82: bytes=32 time=6ms TTL=64

Reply from 74.125.224.82: bytes=32 time=6ms TTL=64

Reply from 74.125.224.82: bytes=32 time=5ms TTL=64

Reply from 74.125.224.82: bytes=32 time=6ms TTL=64

Ping statistics for 74.125.224.82: Packets: Sent = 4, Received = 4,

Lost = 0 (0% loss),

Approximate round trip times in milli-seconds: Minimum = 5ms,

Maximum =6ms, Average = 6ms

Page 40: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

from threading import Thread

import subprocess

from Queue import Queue

num_threads = 4

queue = Queue()

ips = ["11.11.3.230", "11.11.3.229", "11.11.3.228",

"10.0.1.51"]

Page 41: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

#wraps system ping commanddef pinger(i, q):

"""Pings subnet"""while True:

ip = q.get()print "Thread %s: Pinging %s" % (i, ip)ret = subprocess.call("ping -c 1 %s" % ip,

shell=True,stdout=open('/dev/null', 'w'),stderr=subprocess.STDOUT)

Page 42: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

#ToDo: take the return value and check if computer is alive or dead

if ret == 0:

print"%s Alive"% ip

else:

print"%sNot Alive"% ip

q.task_done()

Page 43: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

#Spawn thread pool

for i in range(num_threads):

worker = Thread(target=pinger, args=(i, queue))

worker.setDaemon(True)

worker.start()

#Place work in queue

for ip in ips:

queue.put(ip)

#Wait until worker threads are done to exit

queue.join()

Page 44: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

subprocess.call(args, *, stdin=None, stdout= args:

should be a sequence of program arguments or else a single string. By default, the program to execute is the first item in args if args is a sequence. If args is a string, the interpretation is platform-dependent. It is recommended to pass args as a sequence.

shell:shell argument (which defaults to False) specifies whether to use the shell as the program to execute. If shell is True, it is recommended to pass args as a string rather than as a sequence.On Unix with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt. This includes, for example, quoting or backslash escaping filenames with spaces in them.

If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional arguments to the shell itself.

None, stderr=None, shell=False)

Page 45: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

stdin, stdout and stderr:specify the executed program's standard input, standard output and standard error file handles, respectively.

Valid values are PIPE, an existing file descriptor (a positive integer), an existing file object, and None.

PIPE indicates that a new pipe to the child should be created.

With the default settings of None, no redirection will occur; the child's file handles will be inherited from the parent.

Additionally, stderr can be STDOUT, which indicates that the stderr data from the child process should be captured into the same file handle as for stdout.

Page 46: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

# Import the module

import subprocess

# Ask the user for input

host = raw_input("Enter a host to ping: ")

# Set up the echo command and direct the output to a pipe

host = subprocess.Popen(['ping', '-c 2', host], stdout=subprocess.PIPE)

print host

Page 47: IP address Subnetting Ping command in detail Sub  · PDF fileIP address Subnetting Ping command in detail Threads in Python Sub process in Python

Recommended