By B.A.Khivsara Assistant Professor Computer Department ... · netconfig : step by step network...
Transcript of By B.A.Khivsara Assistant Professor Computer Department ... · netconfig : step by step network...
By B.A.KhivsaraAssistant Professor
Computer DepartmentSNJB’s KBJ COE, Chandwad
Networking commands
Trace Route In detail
Python Program for traceroute
Networking commands
Trace Route In detail
Python Program for traceroute
finger : Display information about the system users. Ex: finger Deepak
ftp : File transfer program. (ftp <remote system name/ip)
ifconfig :Configure a network interface.Ex: ifconfig eth0 address 172.31.2.2 netmask255.255.0.0
ifdown : Shutdown a network interface. Ex: ifdown eth0
ifup : Brings a network interface up. Ex: ifupeth0
netconfig : step by step network configuration program.
netstat : Displays information about the systems network connections, including port connections, routing tables, and more. The command "netstar -r" will display the routing table. (netsat –rn)
nslookup : Used to query DNS servers for information about hosts.
ping : Send ICMP ECHO_REQUEST packets to network hosts. (ping <remote-host-name/ip)
showmount : Show mount information for an NFS server.
ssh : Secure Login (ssh <remote system name/ip>)
tcpdump : Dump traffic on a network. Prints out headers of packets that match the boolean expression. (tcpdump eth0)
telnet :setting up a remote login.
(telnet <remote system name/ip>)
traceroute : Print the route that packets take
to the specified network host.
(traceroute <remote system name/ip>)
route Show or manipulate the IP routing
table. (route, route add, route del)
Networking commands
Trace Route In detail
Python Program for traceroute
Tool used to trace path from source to destination host.
Most traceroute programs, send UDP packets (User Datagram Protocol).
Micrososft tracert sends ICMP echo request (ping) packets.
Unix: traceroute
Cisco IOS: traceroute (trace)
DOS: tracert
Transmits packets with small Time-To-Live (TTL) values.◦ First packets have TTL = 1
◦ Second have TTL = 2
◦ Third have TTL = 3
◦ etc.
TTL
Generates messages from each router used along the path.
Every router that handles a packet subtracts one from the packet's TTL.
If the TTL reaches zero, the packet has expiredand is discarded.
At that point, most routers send an ICMP Time Exceeded message back to the sender -traceroute uses this message.
A TTL value of one should produce a message from the first router; two from the second; etc.
Sender Target
TTL = 1 TTL = 2 TTL = 3 TTL = 4
Traceroute returns these IP addresses
& hostnames (via reverse lookup)
traceroute [ -dFInrvx ] [ -f first_ttl ]
[ -g gateway ] [ -i iface ] [ -m max_ttl ]
[ -p port ] [ -q nqueries ] [ -s src_addr ]
[ -t tos ] [ -w waittime ] [ -z pausemsecs ]
host [ packetlen]
-f Set the initial time-to-live used in the first outgoing probe packet.
-F Set the "don't fragment" bit.
-d Enable socket level debugging.
-g Specify a loose source route gateway (8 maximum).
-i Specify a network interface to obtain the source IP address for
outgoing probe packets.
-I Use ICMP ECHO instead of UDP datagrams.
-m Set the max time-to-live (max number of hops) used in outgoing
probe packets. The default is 30 hops.
-n Print hop addresses numerically rather than symbolically and
numerically
traceroute nis.nsf.net.
traceroute to nis.nsf.net (35.1.1.48), 30 hops max,
38 byte packet
1 helios.ee.lbl.gov (128.3.112.1) 19 ms 19 ms 0 ms
2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39
ms 19 ms
3 128.32.197.4 (128.32.197.4) 40 ms 59 ms 59 ms
4 nic.merit.edu (35.1.1.48) 239 ms 239 ms 239 ms
Hop
Round trip time
Router
C:\WINDOWS>tracert www.husd.k12.ca.us
Tracing route to www.husd.k12.ca.us [206.110.193.5]
over a maximum of 30 hops:
1 1 ms 1 ms 1 ms 192.168.0.1
2 23 ms 32 ms 32 ms adsl-63-198-176-254.dsl.snfc21.pacbell.net [63.198.176.254]
3 20 ms 19 ms 21 ms core4-g3-0.snfc21.pbi.net [216.102.187.130]
4 20 ms 19 ms 19 ms ded2-fa12-0-0.snfc21.pbi.net [209.232.130.5]
5 25 ms 51 ms 21 ms vip-Alameda-Co.cust-rtr.pacbell.net [216.102.184.2]
6 44 ms 37 ms 43 ms 206.110.252.174
7 47 ms 40 ms 40 ms www.husd.k12.ca.us [206.110.193.5]
Trace complete.
Round trip timeHop Router
Networking commands
Trace Route In detail
Python Program for traceroute
import socket
def main(dest_name):
#Getting IP address from Host Name
dest_addr = socket.gethostbyname(dest_name)
port = 33434
max_hops = 30
#initializing receiver and sender packets
icmp = socket.getprotobyname('icmp')
udp = socket.getprotobyname('udp')
ttl = 1while True:
#sending UDP and Receiving ICMP packetsrecv_socket = socket.socket(socket.AF_INET,
socket.SOCK_RAW, icmp)
send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp)
#setting sender packet TTL field to value of the ttlvariable.
send_socket.setsockopt(socket.SOL_IP,socket.IP_TTL,ttl)
recv_socket.bind(("", port))
# code to send pkt using send Socket
send_socket.sendto("",(dest_name,port))
curr_addr = None
curr_name = None
try:
#retrieving the router address from packet_, curr_addr = recv_socket.recvfrom(512)curr_addr = curr_addr[0]try:
#getting hostname of the retrieved addresscurr_name = socket.gethostbyaddr(curr_addr)[0]
except socket.error:curr_name = curr_addr
except socket.error:pass
finally:send_socket.close()recv_socket.close()
#Printing data in the terminal if curr_addr is not None: curr_host = "%s (%s)" % (curr_name, curr_addr) else: curr_host = "*" print "%d\t%s" % (ttl, curr_host)
ttl += 1 if curr_addr == dest_addr or ttl > max_hops: break
if __name__ == "__main__": main('www.google.com')