Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decentralized networking in Python - How?

I want to write a Python script that will check the users local network for other instances of the script currently running.

For the purposes of this question, let's say that I'm writing an application that runs solely via the command line, and will just update the screen when another instance of the application is "found" on the local network. Sample output below:

$ python question.py
Thanks for running ThisApp!  You are 192.168.1.101.
  Found 192.168.1.102 running this application.
  Found 192.168.1.104 running this application.

What libraries/projects exist to help facilitate something like this?

like image 476
Mike Trpcic Avatar asked May 01 '11 03:05

Mike Trpcic


2 Answers

One of the ways to do this would be the Application under question is broadcasting UDP packets and your application is receiving that from different nodes and then displaying it. Twisted Networking Framework provides facilities for doing such a job. The documentation provides some simple examples too.

like image 168
Senthil Kumaran Avatar answered Sep 21 '22 23:09

Senthil Kumaran


Well, you could write something using the socket module. You would have to have two programs though, a server on the users local computer, and then a client program that would interface with the server. The server would also use the select module to listen for multiple connections. You would then have a client program that sends something to the server when it is run, or whenever you want it to. The server could then print out which connections it is maintaining, including the details such as IP address.

This is documented extremely well at this link, more so than you need but it will explain it to you as it did to me. http://ilab.cs.byu.edu/python/

like image 33
Matt Habel Avatar answered Sep 22 '22 23:09

Matt Habel