473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...@yah oo.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(s ocket.AF_INET, socket.SOCK_STR EAM)
s.setsockopt(so cket.SOL_SOCKET , socket.SO_REUSE ADDR, 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 2164
On 2005-02-02, Dana Marcusanu <dm********@yah oo.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
489
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 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)
0
2129
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 to simulate a large-scale, low resolution media facade using individuell video pixels to control lamps mounted into the facade.
3
1412
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 function within my DLL in the VC++ project. I've been reading document over the internet and this
4
2628
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) sets of data seperated by CR/linefeed. At first, it simply seemed like i was getting messed up data, due to encoding it wrong, or using the wrong font, or something like that, but it turns out, when i analyze the byte stream, that the data i get...
0
3707
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) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
4
17803
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 with this code sample: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from WIN32_SerialPort");
0
1427
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 trying to reproduce a very small piece of nmap, since nmap has to get a port's banner in order to figure out the version. However, I haven't been entirely successful. *******************************************************
3
1929
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 up, connect to external websites on external servers and post / remove the data from these other sites. It works fine locally but when uploaded to the BCentral production server, the outgoing requests get shutdown.
4
20213
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 use RegisterRawInputDevices & WM_INPUT but have no idea where to start. Any help greatly appreciated.
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.