Socket ICMP V6 error

2015-01-22 Thread ermanolillo


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


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 = re.search('@@(.*)', d1)

command = data1.group(0)
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 server.py, line 16, in module
s.bind((HOST, 0))
File /usr/lib/python2.7/socket.py, 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: 
http://python.6.x6.nabble.com/Socket-ICMP-V6-error-tp5083962.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Socket ICMP V6 error

2015-01-22 Thread Chris Angelico
On Thu, Jan 22, 2015 at 7:00 PM, ermanolillo ermanoli...@hotmail.com wrote:
 s = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_ICMPV6)

 However I recive the next error:



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

 Could someone please help me?.


For a start, what HOST are you using?

(Point of style: It's unusual to use an all-uppercase name like HOST
for something non-constant - in this case, it's coming from keyboard
input.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Socket ICMP V6 error

2015-01-22 Thread Alain Ketterlin
ermanolillo ermanoli...@hotmail.com writes:

 HOST is  send by the keyboard. It´s the IPv6 address of my interface eth0.
 For example, FE80::0202:B3FF:FE1E:8329.

This is a link-local address, you can't use it just like that (you may
have several interfaces with the same link-local addr). Use getaddrinfo
on FE80...%eth0 (change eth0 to the name of the interface you want to
use) to get a valid 4-tuple. Use that instead of your (HOST,0). You can
also try '::' (kind of inaddr6_any), I don't know if that's what you
want.

But I think you can't bind a raw socket in IPv6. (Not sure, try it and
see.)

-- Alain.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Socket ICMP V6 error

2015-01-22 Thread Chris Angelico
On Fri, Jan 23, 2015 at 2:24 AM, ermanolillo ermanoli...@hotmail.com wrote:
 HOST is  send by the keyboard. It´s the IPv6 address of my interface eth0.
 For example, FE80::0202:B3FF:FE1E:8329.

I can't duplicate the problem. Are you certain that this is indeed an
appropriate address?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Socket ICMP V6 error

2015-01-22 Thread ermanolillo
HOST is  send by the keyboard. It´s the IPv6 address of my interface eth0.
For example, FE80::0202:B3FF:FE1E:8329.



Thanks



--
View this message in context: 
http://python.6.x6.nabble.com/Socket-ICMP-V6-error-tp5083962p5083982.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list