How to set the socket type and the protocol of a socket using create_connection?

Guillaume Comte guillaume.comte10 at gmail.com
Mon Aug 20 11:04:40 EDT 2012


Le lundi 20 août 2012 15:38:14 UTC+2, Hans Mulder a écrit :
> On 20/08/12 14:36:58, Guillaume Comte wrote:
> 
> > In fact, socket.create_connection is for TCP only so I cannot use it for a ping implementation.
> 
> 
> 
> Why are you trying to reimplement ping?

Because I work on a network emulator and I want to check biterros patterns so I need to access the data of the packets. An dsince my test program is written in Python, it's easier to do it in Python.

> 
> 
> 
> All OS'es I am aware of come with a working ping implementation.
> 
> 
> 
> 
> 
> > Does anyone have an idea about how to be able to set a source address for ICMP messages?
> 
> 
> 
> Did you try not setting it?
> 
> 
> 
> The default is probably your own IP address, which is the only
> 
> sensible value anyway.  Or are you trying to cause confusion
> 
> by sending ICMP packets with a forged source address?

No, I want to do it on a machine with aliases as in:

ifconfig em0 10.0.1.1 netmask 255.255.255.0 alias
ifconfig em0 10.0.2.1 netmask 255.255.255.0 alias
ping -c4 -S 10.0.1.1 10.0.2.1


But I think I've found the solution: my_socket.bind((src_addr, 1))

> 
> 
> 
> -- HansM



More information about the Python-list mailing list