Receive packet using socket

Nobody nobody at nowhere.com
Wed Oct 9 13:03:58 EDT 2013


On Wed, 09 Oct 2013 08:37:39 -0700, tspiegelman wrote:

> I am trying to use socket to send / receive a packet (want to recreate
> some functionality of hping3 and port it to windows and mac as a tcp
> ping).  I am having some problems with the recv functionality of socket. 
> Below is the script I am using.  I get an ack from the server (used
> wireshark to ensure it was working) when I run this, but the script
> doesn't see the ack for some reason and the script exits with this error
> or a timeout:

>         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

If you're trying to send/receive individual packets, you need to use
SOCK_RAW (which normally requires root/administrator privilege).

>         s.recv(24)

Alternatively, if you use a normal TCP stream socket, the receiver must
consume all data which is sent to it, and only close the socket after the
writer has closed its end. Depending upon the application-layer protocol,
this may involve some form of QUIT command, or a half-close using
the .shutdown() method.




More information about the Python-list mailing list