how to get a list of all the hosts on the intranet around my workstation?
t at jollybox.de
Sat Jul 16 20:15:19 CEST 2011
On 07/16/2011 06:31 PM, Phlip wrote:
> Yes, pythonistas, sometimes I even amaze myself with the quality of
> question that a computer scientist with a 25 year resume can ask
> around here...
> In my defense, a Google search containing "intranet host" will fan out
> all over the place, not narrow on what I actually need.
> The Use Case is a user wants to ping a nearby host, and I provide a
> list of nearby hosts for the user to pick from. Nothing else. Hosts on
> the outernet need not apply.
> pydhcplib? Shell to a DHCP utility? Ping every server in a range
> around my own?
The obvious solution would be a broadcast ping. However, most hosts will
hot respond to a broadcast ping.
If every host in the network uses DHCP (and you are certain that they
all do), you can query the DHCP server — it should have a list of
Chris mentioned DNS — that may be the most elegant solution, assuming
every host has a (registered) name.
If the network is populated only by Windows machines, you can use the
Windows name resolver. If it is populated only by zeroconf-aware
machines (modern Macs, most modern Linux PCs, Windows PCs with Apple
Bonjour installed), then you can use multicast DNS.
In the end, there is only one way to get all active machines: Ping
everyone on the subnet. You can get the local IP address and netmask
(don't ask me how), and ping every host on the subnet one-by-one. There
are tools that do this (though I can't name one off the top of my head).
This will only miss those hosts that don't respond to pings. (and even
they may be detected by trying to open other ports)
On a homogeneous network, query the infrastructure that is present. If
the network may contain "odd" machines that don't use DHCP, or something
like that, you'll have to ping the lot.
More information about the Python-list