top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Use of python sockets for capturing non-python source?

0 votes

Can python sockets be used to capture IP traffic when the traffic is originating from a non-python source?

Using a Lantronix UDS-1100 serial to IP converter. The goal is to write a small proof of concept piece in Python to capture serial data output by this device over IP.

I've done a couple test projects using sockets in python, but they were all done between python processes (python > python): listen() on one end, and connect(), sendall() etc on the other.

I think I can use sockets for this project, but before I invest a bunch of time into it, wanted to make sure it is a viable solution.

Can python sockets be used to capture IP traffic when the traffic is originating from a non-python source? I have full control over the IP and port that the device sends the serial data to, but there will be no python connect() initiated by the client. I can pre-pend then serial data with some connect() string if needed.

If sockets won't work, please recommend another solution...guessing it will be REST or similar.

posted May 16, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Python just exposes the underlying OS socket interface. There is nothing special about sockets in Python. The whole point is to connect
heterogeneous systems. I can use Python on Windows to create a client that will connect to a service written in C running on Solaris or to something written in Java running on Linux.

answer May 16, 2013 by anonymous
Similar Questions
+5 votes

I am currently trying to make and use a list/array of sockets in a program. So I have declared an array as follows:

myCSocks = ['CSock1', 'CSock2', 'CSock3', 'CSock4', 'CSock5']

and I am trying to use my array elements as follows:

myCSocks[i], addr = serverSocket.accept()
message = myCSocks[i].recv(1024)

I am getting the following error:

Traceback (most recent call last):
 File "./", line 22, in 
 message = myCSocks[i].recv(1024)
AttributeError: 'str' object has no attribute 'recv'

This kind of makes sense to me, it is saying that my array elements are of type String and are not sockets. So I understand what my problem is but I do not know how to remedy it. I have googled "list of sockets python" but did not find anything. Any help will be greatly appreciated.

+2 votes

I'm trying out Tkinter with the (non object oriented) code fragment below: It works partially as I expected, but I thought that pressing "1" would cause the program to quit, however I get this message:

TypeError: quit() takes no arguments (1 given),

I tried changing quit to quit() but that makes things even worse. So my question: can anyone here help me
debug this?

#!/usr/bin/env python
import Tkinter as tk
def quit():
root = tk.Tk()
label = tk.Label(root, text="Hello, world")
label.bind("", quit)
0 votes

I want to monitor printers for events such as the completion of printing. If the printer initiates an SNMP trap event when the job has finished printing, how can I capture this?

Presumably I need some sort of deamon to listen for these trap messages. I have looked at pySNMP but am not sure if this can be used to capture SNMP trap events from the printer.

0 votes

I am to start a new free-time project in the next couple of weeks. I am ready to use open accessible Python modules not wanting to reinvent the wheel :-)

Is there any repository where I can find Python modules not being part of the standard distribution? I have some hits by Google but that seems to be far from complete.

+4 votes

I just started rewritting my project from python 2 to python 3. I noticed that there are these new parameter and return value annotations. I have docstrings everywhere in my project, but I plan to convert many of them into annotations. The question is: what kind of auto documenting system should I use for this? Previously I have used Sphinx. Is it okay to use that for python 3 source code? Is there a better alternative?