Hello everyone,
I want to use socket.create_connection(...) to set a source address in a ping
implementation in python.
But how can I then set the type and the protocol? Because, before, I did:
icmp = socket.getprotobyname("icmp")
my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
In fact, socket.create_connection is for TCP only so I cannot use it for a ping
implementation. Does anyone have an idea about how to be able to set a source
address for ICMP messages?
--
http://mail.python.org/mailman/listinfo/python-list
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
Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error
message: "socket.error: [Errno 49] Can't assign requested address"...
I've tried to change the protocol to IPPROTO_RAW. Here is a simple example of
the code:
import socket
import os
import struct
import time
import sele
Le mercredi 22 août 2012 04:10:43 UTC+2, Dennis Lee Bieber a écrit :
> On Tue, 21 Aug 2012 10:00:28 -0700 (PDT), Guillaume Comte
>
> declaimed the following in
>
> gmane.comp.python.general:
>
>
>
> A later follow-up
>
> > Unfortunatly, my_socket
I've managed to build the IP header. I've put the source and destination
addresses in this header but it doesn't change the real source address...
I'm trying to read the ping source code but I'm lost...
--
http://mail.python.org/mailman/listinfo/python-list
Le mercredi 22 août 2012 11:03:11 UTC+2, Hans Mulder a écrit :
>
> On my laptop, 0 appears to be the only port number that bind accepts
>
> for a raw socket. Other numbers I tried all raise "socket.error:
>
> [Errno 49] Can't assign requested address".
>
>
>
> But this might depend on your