Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56498 > unrolled thread

Receive packet using socket

Started bytspiegelman@amplify.com
First post2013-10-09 08:37 -0700
Last post2013-10-09 18:03 +0100
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Receive packet using socket tspiegelman@amplify.com - 2013-10-09 08:37 -0700
    Re: Receive packet using socket tspiegelman@amplify.com - 2013-10-09 09:07 -0700
    Re: Receive packet using socket Nobody <nobody@nowhere.com> - 2013-10-09 18:03 +0100

#56498 — Receive packet using socket

Fromtspiegelman@amplify.com
Date2013-10-09 08:37 -0700
SubjectReceive packet using socket
Message-ID<11f1aa94-8d04-40da-a0da-48fcbb7e3e13@googlegroups.com>
Hey all,

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:

  Traceback (most recent call last):
  File "./tcpgcmtesttristedit.py", line 21, in <module>
    s.recv(1024)	
socket.error: [Errno 104] Connection reset by peer

Here is the script:

import socket
import time

numberofpackets = int(raw_input("How many packets should be sent?\n> "))
hostname = 'mtalk.google.com'
port = 5228

for i in range(numberofpackets):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(4)
        s.connect((hostname, port))
        s.send('data')
        start_time = time.time()
        s.recv(24)
        print time.time() - start_time
        s.close()


Any help would be much appreciated.  Thanks, Tom.

[toc] | [next] | [standalone]


#56501

Fromtspiegelman@amplify.com
Date2013-10-09 09:07 -0700
Message-ID<55af799c-806b-4506-9002-10dd02d79408@googlegroups.com>
In reply to#56498
BTW what I am trying to accomplish is easily done in hping3 using this command:
hping3 mtalk.google.com -S -p 5228 

I just want those same kind of results using python so I can make an exe out of it.  

On Wednesday, October 9, 2013 11:37:39 AM UTC-4, tspie...@amplify.com wrote:
> Hey all,
> 
> 
> 
> 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:
> 
> 
> 
>   Traceback (most recent call last):
> 
>   File "./tcpgcmtesttristedit.py", line 21, in <module>
> 
>     s.recv(1024)	
> 
> socket.error: [Errno 104] Connection reset by peer
> 
> 
> 
> Here is the script:
> 
> 
> 
> import socket
> 
> import time
> 
> 
> 
> numberofpackets = int(raw_input("How many packets should be sent?\n> "))
> 
> hostname = 'mtalk.google.com'
> 
> port = 5228
> 
> 
> 
> for i in range(numberofpackets):
> 
>         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
>         s.settimeout(4)
> 
>         s.connect((hostname, port))
> 
>         s.send('data')
> 
>         start_time = time.time()
> 
>         s.recv(24)
> 
>         print time.time() - start_time
> 
>         s.close()
> 
> 
> 
> 
> 
> Any help would be much appreciated.  Thanks, Tom.

[toc] | [prev] | [next] | [standalone]


#56505

FromNobody <nobody@nowhere.com>
Date2013-10-09 18:03 +0100
Message-ID<pan.2013.10.09.17.03.57.186000@nowhere.com>
In reply to#56498
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web