# getting IP and MAC of all peripherals



## Drahos Madar (Jun 26, 2017)

Hey guys

I'm new @ BSD and this forum - so sorry if my question is duplicated or somehow not in line with rules of this web (as far as I have investigated none of those apply)

I was asked to write a program (python preff) which will return IP and MAC of all peripherals connected to server (multimedia devices in bus) and topography - schema of connection between those devices. 

I assume something like that has to exist already, but I did not managed to find it here, nor google it. 

So your expertise or directions would be very much appreciated.


----------



## Phishfry (Jun 26, 2017)

Check out /sysutils/sysinfo
It has a network section that covers MAC and IP's.


----------



## Phishfry (Jun 26, 2017)

From the command line:
`ifconfig | grep ether ; ifconfig | grep inet`


----------



## Phishfry (Jun 26, 2017)

Most multimedia devices would not have a MAC address but a PCI address. That can be found with `pciconf -l` and  USB devices have a UGEN schema that can be discovered with `usbconfig dump_device_desc`


----------



## SirDice (Jun 27, 2017)

Phishfry said:


> Most multimedia devices would not have a MAC address but a PCI address.


I think the OP means multimedia devices attached to the network. Like set-top boxes and media-streamers.

For network devices, ping the whole network and parse the output of `arp -an`.


----------



## usdmatt (Jun 27, 2017)

First time post and a question that isn't really specific to FreeBSD. I'll assume that you _are_ actually trying to do this on FreeBSD.

If you mean devices actually connected to the FreeBSD machine (as in sending or receiving data from the server), you can look at the "Foreign Address" column in `netstat -n` to see any clients connected to the server. As SirDice says `arp -an` will show the MAC address of any LAN connected clients.

To find all devices on the LAN (those that respond to ping at least) you can do as SirDice says and just ping every address then check arp output.

There's no obvious way to work out the topology of the network or how devices are connected to each other. Clients could be directly cabled to FreeBSD, go through a switch, a bridge, etc and FreeBSD has no real way of knowing that.


----------

