473,396 Members | 2,018 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,396 software developers and data experts.

getting data from a port in use

Yes. I want to write a very small web sniffer that gets data from a
specified port. I already looked at some of the existing ones on Internet,
but they are not in Python (I am trying to learn Python!) and they have a
lot more features that I want. Thanks for your suggestion. I will check
out pcap library.

Dana

On 2005-02-01, Dana Marcusanu <dmarcus...@yahoo.com> wrote:
I am trying to use Python to get the data received at a specific port (in use) on my computer.
What do you mean "in use"? You mean you want to evesdropt on
data that's being sent to an existing connection? If so,
you'll need to use something like the pcap library.
I already tried below code which seems to hang at the
statement accepting connections. I don't know what else I can try. Any
suggestions will be welcome. import socket, select, os PORT = 2005
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((socket.gethostname(), PORT))
s.listen(1)
work_socket, addr = s.accept()
data = s.recv(1024)
No matter what you're trying to do, this isn't right. Once the
connection has been accepted, you have to read data from the
socket returned by the accept() call.
print data
s.close()


--
Grant Edwards grante Yow! Actually, what
at I'd like is a little
toy
visi.com spaceship!!

__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
Jul 18 '05 #1
1 2127
On 2005-02-02, Dana Marcusanu <dm********@yahoo.com> wrote:
Yes. I want to write a very small web sniffer that gets data
from a specified port.
OK, know we know what you're actually trying to do. You should
have told us that to start with rather than leading us down the
wrong path with your little Python program. When asking for
help, always clearly describe your _problem_ first. Asking
what's wrong with a proposed solution without clearly
describing the problem you're trying to solve just wastes time:

http://www.catb.org/~esr/faqs/smart-questions.html
I already looked at some of the existing ones on Internet, but
they are not in Python (I am trying to learn Python!)
You picked a rather tricky little project.
and they have a lot more features that I want. Thanks for your
suggestion. I will check out pcap library.


Pcap is your only hope unless you want to do a lot of rather
nasty low level stuff (for which you'll probably have to write
a bunch of C code that does all the things that libpcap does).

You can't use the normal Python socket API to sniff data.

You _could_ use popen to run tcpdump (which in turn uses pcap)
and then parse the output from pcap. I've done both, and IMO
using pcap directly is a lot easier. It's also your only hope
of keeping up with any amount of traffic.

http://sourceforge.net/projects/pylibpcap
http://sourceforge.net/project/showf...ckage_id=13826

Once upon a time, there was a rumor that somebody had a Win32
version of pylibpcap.

Good luck. :)

--
Grant Edwards grante Yow! Did an Italian CRANE
at OPERATOR just experience
visi.com uninhibited sensations in
a MALIBU HOT TUB?
Jul 18 '05 #2

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

Similar topics

1
by: Dana Marcusanu | last post by:
Hi to all, I am trying to use Python to get the data received at a specific port (in use) on my computer. I already tried below code which seems to hang at the statement accepting connections. I...
0
by: Stefan Tietke | last post by:
Hi all, for a realtime simulation of a video installation we want to use Quicktime to read video data from a file or stream and process the data in a realtime Gameblender model. We are trying...
3
by: Marty | last post by:
Hi, I have this DLL made with VB.NET made as a Class Library project. I know this is managed code. I have my other made with VC++.NET, unmanaged code. The point is that I want to use...
4
by: Iceman.Aragorn | last post by:
I'm having an odd problem where im reading input from a comm port (the maker of the software that exports the data TO the comm port is unhelpful). What im reading is fixed length (13 character)...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
4
by: Frank | last post by:
Hello, how to get information about all serial ports in the PC? I use the following code, but i got only the data of the FIRST serial port. All other serial port information are not available...
0
by: mmcgee00 | last post by:
Hi, Currently, I am trying to get different service banner by connecting to different ports using python (code below). The versions I am working with are python 4.2.1 and fedora core 4. I am...
3
by: TC | last post by:
Hey All, I have some classes that I recently built for a website which uses the HttpWebRequest & HttpWebResponse objects from the System.Net namespace. Basically, the classes rap submitted data...
4
by: Gerry19 | last post by:
Hi All, I'm trying to monitor data passed from a USB Barcode scanner but I can't find any decent code examples of what I need to do, including any references I need to include. I know I need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.