all ip addresses of machines in the local network

Amit Khemka khemkaamit at gmail.com
Thu Aug 24 07:19:56 EDT 2006


On 8/24/06, Amit Khemka <khemkaamit at gmail.com> wrote:
> On 23 Aug 2006 21:46:21 -0700, damacy <wegein at gmail.com> wrote:
> > hi, sandra.
> >
> > no, it's not as complicated as that. all i want to do is to load a
> > database onto different machines residing in the same network. i hope
> > there is a way doing it. or perhaps i have a poor understanding of how
> > networks work.
> >
>
> I expect that you would know the IP range for your network. Then you
> can simply 'ping' each IP in the range to find wether its alive.
> Moreover by your description I guess you would actually want to find
> all machines in your network that run a particular network service, to
> allow you to "distribute the database". In such case you can use
> "nmap" with -p option, to find all the machines which are listening on
> the particular port.
>
> hth,
> amit.
It seems that I am not too busy, so here is a code which may work with
a few tweaks here and there:
_________________________________________________________________________
import os
# base and range of the ip addresses
baseIP = "10.0.0."
r = 6
interestingPort = 22 # port that you want to scan
myIPs = []

for i in range(r):
        ip = baseIP+str(i)  # It may need some customization for your case
        print "scanning: %s" %(ip)
        for output in os.popen("nmap %s -p %s" %(ip,
interestingPort)).readlines():
                if output.__contains__('%s/tcp open'
%interestingPort):  # i guess it would be tcp
                        myIPs.append(ip)
__________________________________________________________________________
print myIPs


hth,
amit.
-- 
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.



More information about the Python-list mailing list