G
G
gd1xza2020-12-30 20:35:40
linux
gd1xza, 2020-12-30 20:35:40

icmp response not coming?

I have a python code that accepts icmp pings and sends back a response. Pings come and the answer is not.

import socket
r = socket
s = socket.socket(r.AF_INET, r.SOCK_RAW, r.IPPROTO_ICMP)
#s.setsockopt(socket.SOL_IP, socket.IP_HDRINCL,0)
while True:
 data,addr = s.recvfrom(4096)
 d = data.split(b"\x08\x00")[1]
 chk = bytes([d[0]]),bytes([d[1]])
 id = bytes([d[2]]),bytes([d[3]])
 seq = bytes([d[4]]),bytes([d[5]])
 payload = b''
 for x in d:
  if x == d[0]:
   continue
  elif x == d[1]:
   continue
  elif x == d[2]:
   continue
  elif x == d[3]:
   continue
  elif x == d[4]:
   continue
  elif x == d[5]:
   continue
  else:
   payload += bytes([x])

 print("Checksum: ",chk)
 print("Id: ",id)
 print("Seq num: ",seq)
 print("Payload: ",payload.decode("utf-8"))
 rsp = b"\x00\x00\x00\x00"+id[0]+id[1]+seq[0]+seq[1]+payload
 print(rsp)
 s.sendto(rsp,addr)

At the output from the server, nothing is visible either, that is, the kernel does not let the packet through.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Talyan, 2020-12-30
@flapflapjack

the kernel does not let the packet through.

Well icmp type 8 is the request and type 0 is the response. You may have a packet blocked in iptables by a rule like
iptables -A OUTPUT -p icmp -m icmp --icmp-type 8 -j DROP

Do it first
iptables -F
and try again.
PS I'm not savvy in python, so there may be an error in the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question