Socket ICMP V6 error

ermanolillo ermanolillo at
Thu Jan 22 09:00:49 CET 2015

I've made a snniferr for a ICMP socket that works with IPv4. This is the

import sys
import socket
import struct
import select
import time
import signal
import re

HOST = raw_input("Enter the interface to listen: ")

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
s.bind((HOST, 0))
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

print "Server Started......"
for i in range(1,2000):

data = s.recvfrom(65565)
d1 = str(data[0])
data1 ='@@(.*)', d1)

command =
cmd = command[2:]
if i%2 == 0:
d = data[1]
d1 = str(d)
ip = d1[2:-5]

print cmd 
print ip

I have done a modification to adapt it to IPv6:


s = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_ICMPV6)

However I recive the next error:


File "", line 16, in <module>
s.bind((HOST, 0))
File "/usr/lib/python2.7/", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument

Could someone please help me?.

Thanks in advance

View this message in context:
Sent from the Python - python-list mailing list archive at

More information about the Python-list mailing list