[Tutor] getting network device names
Mats Wichmann
mats at wichmann.us
Fri May 14 09:41:53 EDT 2021
On 5/14/21 7:00 AM, nathan Smith wrote:
> Hi list,
>
>
> I figured I'd ask here in case I'm missing something.
>
> I'm trying to write a small program that would be able to get a list of
> devices connected to the same one as my laptop, EG the devices on the
> router and display that in a list of IP and device name.
>
> I'm running python 3.8 on windows and so far can get a list of IP
> addresses through the arp -a command and putting it through os.popen to
> process the results.
>
> As far as I can see though the only way to get the device names is
> through nmap which does not come by default on windows and doesn't look
> like it's made to be distributed as part of a package.
>
> I know though that socket.gethostname() returns my local computer's
> name, so wonder if I am missing something?
>
> Maybe I can do some form of call to the dns of the router itself?
>
> socket.gethostbyaddr(an-ip-address) times out for local IP addresses.
not really a Python question... Windows doesn't return hostnames, only
ip addresses, from the arp command. gethostbyaddr() could be useful, or
you could call out to the system again and use the nslookup Windows
command, but both depend on there being someone to answer - a properly
configured dns server for your local domain, and/or a hosts file that
has entries to do that transformation of ip to name.
More information about the Tutor
mailing list