Search code examples
pythonnetwork-programmingscapyttl

scapy ICMP show ( ttl ) only


I am trying to send a icmp packet to a machine in my network but I need to show the ttl only

the command that I used : q = sr1(IP(dst="192.168.1.8")/ICMP())

Then I run : q.show2()

Output :

###[ IP ]### 
  version= 4
  ihl= 5
  tos= 0x0
  len= 28
  id= 8236
  flags= 
  frag= 0
  ttl= 128
  proto= icmp
  chksum= 0x9757
  src= 192.168.1.8
  dst= 192.168.1.5
  \options\
###[ ICMP ]### 
     type= echo-reply
     code= 0
     chksum= 0xffff
     id= 0x0
     seq= 0x0

How to show only the ttl !!


Solution

  • You can use, if you want some advanced formatting:

    q.sprintf("%IP.ttl%")
    

    Demo:

    a = IP()
    a.sprintf("%IP.ttl%")
    '64' 
    

    But you could also just get the attribute:

    a = IP()
    ttl = a[IP].ttl