1

I created the fllowing code in order to send a packet to the address www.google.com, but I'm not getting any answer.

CODE


from scapy.all import IP, ICMP, sr1 

ip_layer = IP(src='192.168.224.131',  dst='www.google.com')  

#rint(ip_layer.show()) 

icmp_req = ICMP()

#print(icmp_req.show())  

packet = ip_layer / icmp_req 

#print(packet.show()) 

received_packet = sr1(packet, timeout=2) 

if received_packet: 
    print(received_packet.show()) 

OUTPUT

Begin emission:
.Finished sending 1 packets.

Received 1 packets, got 0 answers, remaining 1 packets

1 Answer 1

2

This code works on my machine (i.e. this is likely unique to your computer/network). This means one of any number of things could be wrong:

  • The IP address you're using in src is wrong (you can check this with ifconfig on linux and ipconfig on windows).
  • the timeout is too low (I've sometimes seen issues at 2s timeout and changing to 5 fixes). I see output similar to yours if I set the timeout to 0.001 (i.e. google isn't going to respond to me in 1ms).
  • Your firewall (OS or router) could be blocking this traffic.
  • Some other network problem like DNS or the traffic being dropped. Note that pings are low-priority traffic for most routers, so they'll occasionally drop, but that doesn't imply that normal traffic will experience the same loss.

This is the response I got after changing the src IP address:

bash-5.0$ python temp.py
Begin emission:
....Finished sending 1 packets.
.*
Received 6 packets, got 1 answers, remaining 0 packets
###[ IP ]### 
  version   = 4
  ihl       = 5
  tos       = 0x0
  len       = 28
  id        = 0
  flags     = 
  frag      = 0
  ttl       = 50
  proto     = icmp
  chksum    = 0xfe6
  src       = 172.217.9.132
  dst       = 192.168.1.246
  \options   \
###[ ICMP ]### 
     type      = echo-reply
     code      = 0
     chksum    = 0x0
     id        = 0x0
     seq       = 0x0
###[ Padding ]### 
        load      = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

None
1
  • Thank you, now it works. I try to use my tablet as hotspot instead my router.
    – Andrea
    Commented May 26, 2020 at 6:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.