473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

sniffer in python

Hi!
I made a little, simple program that sends strings over an ICMP packet.
The source here:
http://billiejoex.altervista.org/a1.txt

Now all I need is create a simple network sniffer able to sniff the ICMP
packets and print the strings on the screen.
A useful library known in a lot of other programming languages is 'libcap'
(winpcap for win32 platforms).
For python exist a porting called pcapy:
http://oss.coresecurity.com/projects/pcapy.html
....that I'd like to use BUT... all the examples reported on the sites don't
works!!
Is there someone who has already created a network sniffer in python?
It shouldn't be too much difficult...

Best regards
Aug 15 '05 #1
6 3480
billiejoex wrote:
For python exist a porting called pcapy:
http://oss.coresecurity.com/projects/pcapy.html
...that I'd like to use BUT... all the examples reported on the sites don't
works!!


It usually helps to describe *in what way* things don't work.

Do they crash? If so, provide the full traceback.

Do they not install? If so, provide error messages.

Do they appear to run but without visible signs of activity? If so, say
so... and describe exactly what options you were using, what platform
and version of platform, Python, and library you are using, and any
other conditions relevant to the situation.

Help us help you...

(Alternative suggestion: use whatever mailing list is provided for that
specific project, if there is one, so you get access to more people with
direct knowledge of what might go wrong.)

-Peter
Aug 15 '05 #2
Thank you for your fast reply. You're right. I'll be more specific, sorry.
The example source is the one you can find on the 'Impacket' page on the
same site of pcapy:
http://oss.coresecurity.com/impacket/sniff.py
I use a Win XP prof sp2 system, python ver. 2.4.1.
Here's the output:

C:\Python24>1.py
Traceback (most recent call last):
File "C:\Python24\1.py", line 107, in ?
main(filter)
File "C:\Python24\1.py", line 88, in main
dev = getInterface()
File "C:\Python24\1.py", line 81, in getInterface
print '%i - %s' % (count, iface)
File "C:\Python23\lib\encodings\cp850.py", line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position
4-19: ch
aracter maps to <undefined>

For python exist a porting called pcapy:
http://oss.coresecurity.com/projects/pcapy.html
...that I'd like to use BUT... all the examples reported on the sites
don't works!!


It usually helps to describe *in what way* things don't work.

Do they crash? If so, provide the full traceback.

Do they not install? If so, provide error messages.

Do they appear to run but without visible signs of activity? If so, say
so... and describe exactly what options you were using, what platform and
version of platform, Python, and library you are using, and any other
conditions relevant to the situation.

Help us help you...

(Alternative suggestion: use whatever mailing list is provided for that
specific project, if there is one, so you get access to more people with
direct knowledge of what might go wrong.)

-Peter

Aug 15 '05 #3
billiejoex wrote:
Thank you for your fast reply. You're right. I'll be more specific, sorry.
The example source is the one you can find on the 'Impacket' page on the
same site of pcapy:
http://oss.coresecurity.com/impacket/sniff.py
I use a Win XP prof sp2 system, python ver. 2.4.1.
Here's the output:

C:\Python24>1.py
Traceback (most recent call last):
File "C:\Python24\1.py", line 107, in ?
main(filter)
File "C:\Python24\1.py", line 88, in main
dev = getInterface()
File "C:\Python24\1.py", line 81, in getInterface
print '%i - %s' % (count, iface)
File "C:\Python23\lib\encodings\cp850.py", line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position
4-19: ch
aracter maps to <undefined>


Helping you learn to troubleshoot from tracebacks: look at the line
preceding the failing call. Can you guess anything about what in that
line might be causing an encode() call? The count variable is,
presumably, just an integer, so %i wouldn't like have to do more than
convert it to a string. %s, however, asks for "iface" to be turned into
a string... if it were not already a string (i.e. it's a unicode?) it
would have to be encoded. What does iface contain and where did it come
from? Can you make it be just a string? Does that change or fix anything?

-Peter
Aug 16 '05 #4
Thanks for your help. Like you suggested I converted the integer value in a
string one by using the repr() funtion applied on the print:

print '%d \n %s' %(count, repr(iface))

The program now permit me to select the interface. The output is in a
strange hex-similar form:

C:\Python24>test.py
0
u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e \u6972\u4e63\u6964\u5773\u6e61\u6441\u7061\u6574r\ u445c\u7665\u6369\u5c65\u504e\u5f46\u317b\u4534\u3 544\u3642\u2d31\u3030\u3942\u342d\u4441\u2d39\u334 1\u4345\u382d\u3033\u3246\u3938\u3241\u4531\u7d44\ u5c00\u6544\u6976\u6563\u4e5c\u4650\u7b5f\u3541\u3 630\u3934\u3434\u452d\u4230\u2d37\u3634\u3239\u382 d\u4237\u2d35\u4630\u3133\u4244\u3933\u3532\u3943} \u445c\u7665\u6369\u5c65\u504e\u5f46\u377b\u4337\u 3644\u3034\u2d31\u3841\u3143\u342d\u3743\u2d43\u32 41\u4633\u432d\u3731\u3037\u3538\u3234\u4538\u7d34 '1 u'\u6547\u656e\u6972\u2063\u644e\u7369\u6157\u206e \u6461\u7061\u6574r\u4d56\u6177\u6572\u5620\u7269\ u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7 061\u6574r\u4d56\u6177\u6572\u5620\u7269\u7574\u6c 61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574 r\u564e\u4449\u4149\u6e20\u6f46\u6372\u2065\u434d\ u2050\u654e\u7774\u726f\u696b\u676e\u4120\u6164\u7 470\u7265\u4420\u6972\u6576\u2072\u4d28\u6369\u6f7 2\u6f73\u7466\u7327\u5020\u6361\u656b\u2074\u6353\ u6568\u7564\u656c\u2972 'Please select an interface: 0When I select the interface (0 or 1) I encounter an encoding error:Traceback (most recent call last): File "C:\Python24\test.py", line 108, in ? main(filter) File "C:\Python24\test.py", line 92, in main p = open_live(dev, 1500, 0, 100)UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15:ordinal not in range(128)- How con I resolve this encoding problem?- How can I display the interface names in a 'human' form?Best regardsbillie> Helping you learn to troubleshoot from tracebacks: look at the linepreceding the failing call. Can you guess anything about what in that linemight be causing an encode() call? The count variable is, presumably, justan integer, so %i wouldn't like have to do more than convert it to a string.%s, however, asks for "iface" to be turned into a string... if it were notalready a string (i.e. it's a unicode?) it would have to be encoded. Whatdoes iface contain and where did it come from? Can you make it be just astring? Does that change or fix anything?>> -Peter

Aug 16 '05 #5
Sorry... the text has been wrong formatted. Read this, plz >>>

Thanks for your help. Like you suggested I converted the integer value in a
string one by using the repr() funtion applied on the print:
print '%d \n %s' %(count, repr(iface))
The program now permit me to select the interface. The output is in a
strange hex-similar form:
http://billiejoex.altervista.org/test.txt

When I select the interface (0 or 1) I encounter an encoding error:
Traceback (most recent call last):
File "C:\Python24\test.py", line 108, in ?
main(filter)
File "C:\Python24\test.py", line 92, in main
p = open_live(dev, 1500, 0, 100)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15:
ordi
nal not in range(128)

- How con I resolve this encoding problem?
- How can I display the interface names in a 'human' form?

Best regards
billie
Aug 16 '05 #6
Moreover the getInterface() function seems to be unexistent:
from pcapy import *
getInterface()

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'getInterface' is not defined

Maybe it can be used only on *nix platforms?
Aug 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: AMC | last post by:
Hi, I need to code an asp based browser sniffer. It needs to detect if a browser can support css and if not redirect to a different site. Does anyone have sample code that does this? thx
0
by: billiejoex | last post by:
Hi all. The source below is a simple icmp sniffer made with pcapy. To decode packets I'm using the EthDecoder() function that returns a rapresentation of the packet including ICMP type, ICMP code,...
5
by: David Baker | last post by:
Hi all I am very new to ASP.Net. I am trying to create a sniffer for our program. We want our users to click our sniffer and hopefully the sniffer will check their computer against our...
2
by: Laurent Laporte | last post by:
hello, I'm using cvs standard module under Python 2.3 / 2.4 to read a CSV file. The file is opened in binary mode, so I keep the end of line terminator. It appears that the csv.Sniffer force...
6
by: Andreas Jung | last post by:
Does anyone know of a Python module that is able to sniff the encoding of text? Please: I know that there is no reliable way to do this but I need something that works for most of the case...so...
2
by: kali | last post by:
this is kali a new member to this forum.. iam an undergrad studd and wrking with a opacket sniffer to capture data transmitted using a hardware... the file saved in the sniffer is a binary file...
4
by: cHacker | last post by:
Hello, there are some ICQ sniffers available on Internet, i am curious about how to get ICQ talk(text)? someone has any idea to get the icq talks(texts)? thanks
4
by: chazzy69 | last post by:
Hello i am a little new c++, i know most of the basics now and im interest in making a sniffer for my router to see any and all connections made to the router from the outside world, my router does...
0
by: showellshowell | last post by:
Hi everybody, I'm looking for a very simple HTTP debugging sniffer in Python-- hopefully 200 lines of less--that allows me to write simple methods to inspect requests and responses. It would...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.