Determine devices attached to router

Post your questions and help other users.

Moderator: Martin

Post Reply
Mgmcderm
Posts: 4
Joined: 09 Jan 2017 03:19

Determine devices attached to router

Post by Mgmcderm » 02 Dec 2018 20:30

I would like to program old cell phone to put our HVAC system in vacation mode when our cell phones are not connected to our router. I can get a gui up from our router web page, but how can I get a list of Mac addresses of attached devices to automatic?

User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Re: Determine devices attached to router

Post by beelze » 03 Dec 2018 17:20

If you have linux-based router with ssh access, you can use action Execute SSH Command, something (roughly) like this:

Code: Select all

iw dev ath0 station dump | awk '{if($1=="Station") printf "%s ",$2; if($1~"inactive") printf "%s\n",$3}'
output will be like this (MAC ms-of-inactive-time):
xx:yy:zz:c9:d9:73 10
xx:yy:zz:a7:63:05 4120
xx:yy:zz:c0:8b:79 2380
xx:yy:zz:3b:05:60 60
xx:yy:zz:75:37:a3 7180


you can parse this output and do something based on MAC presence and (maybe) inactivity time.

P.S. you can get your actual device name (Interface) for iw dev $DEVICE … from:

Code: Select all

# iw dev
phy#1
	Interface ath1
		ifindex 8
		wdev 0x100000002
		addr xx:yy:zz:e7:b7:e9
		ssid MYSSID
		type AP
		channel 149 (5745 MHz), width: 20 MHz, center1: 5745 MHz
phy#0
	Interface ath0
		ifindex 7
		wdev 0x2
		addr xx:yy:zz:e7:b7:e8
		ssid MYSSID2
		type AP
		channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Determine devices attached to router

Post by Desmanto » 09 Dec 2018 17:58

If you can get the GUI / web based UI from the router, and your router doesn't support any SSH or telnet; you can use HTTP request to retrieve the GUI. It is quite difficult, as it varies depends on the router. You also have to mimic the login session using the proper username/password. Then parse the response using regex to list out all the mac.

I use the similar one to retrieve all the mac address and hostname from it. So I know whose devices are connected at the moment (I have given each devices names based on the mac address).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply