Finding Live Nodes on LAN using Python

aki92 picture aki92 · Mar 17, 2013 · Viewed 19.1k times · Source

I am creating a Messenger which is same as IP Messenger in Python 2.7 and Windows.

I want the same functionality as IP Messenger uses in finding the systems running same software over LAN but I am unable to understand the technique.

Can someone please help me to solve the problem of Finding the computers IP address or host name running same software over the LAN using Python 2.7 and Sockets Library.

Please suggest something which can be implemented on Windows not like Nmap(limited to linux) and it will be very helpful if solution is Python's Socket Library code.

Answer

aki92 picture aki92 · Mar 19, 2013

" net view " command of Windows command prompt solved my problem stated in question.

By this command I am able to find all the computers connected to my computer through LAN and then I will send packets to all computers and computers replying to my packet would be the systems running same software as I am running which completely solved my problem.

This code lists out all the computers host names connected with my computer over LAN.

import os
os.system('net view > conn.tmp')
f = open('conn.tmp', 'r')
f.readline();f.readline();f.readline()

conn = []
host = f.readline()
while host[0] == '\\':
    conn.append(host[2:host.find(' ')])
    host = f.readline()

print conn
f.close()