ARP and Bonjour to build list of user devices


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers ARP and Bonjour to build list of user devices
# 1  
Old 03-12-2017
ARP and Bonjour to build list of user devices

Hi,
I want to build a list of the devices that are connected to my network and refresh that list every 10th minute (using an RPi with Raspbian). The host names are obtained by using Bonjour which is easily installed by:
Code:
sudo apt-get install libnss-mdns

To build the list manually, I do like this:

1. Find the broadcast address (I sometimes change subnet, so the address could change and the ARP table has to be refreshed at every run):
Code:
ip address show | grep eth0 | grep brd | awk '{print $4}'

2. Ping the broadcast address to build ARP table:
Code:
ping <broadcast address>

3. Print the desired fields of the ARP table:
Code:
arp -a | awk '{print $4 " " $1}'

This produces the desired output which would look something like this:
Code:
00:11:22:33:AA:BB iPhone1
00:11:22:33:AA:BC my Laptop
00:11:22:33:AA:BD ?
...

I want to make this process automated so that I get an updated list every 10th minute. Does someone know a good way of doing this? Have tried to script it but it seems I can't ping a stored IP address.

Cheers!
Sam
# 2  
Old 03-12-2017
Hi,

In general, if a command works at the shell prompt, it should work if that same command is put in a script that is run by that same shell. What might be happening here perhaps is that paths when running via crontab might not be what you'd expect.

If you try in your script putting full absolute paths to all binaries and files, does it then work OK via a crontab entry ? That's probably the first thing to try, since if this approach is working for you at the command line, it should (generally speaking) work in a script as well.

Also make sure the shebang line at the top of your script matches the shell you expect to use to run the script (so #!/bin/bash for Bash, for instance), in case there is a difference between your own shell and the system default shell, or the shell the user is running as in cron.
This User Gave Thanks to drysdalk For This Post:
# 3  
Old 03-12-2017
Thanks drysdalk. Had some errors when converting the obtained broadcast address. Just replaced step 1 and 2 with:
Code:
ping -i eth0 255.255.255.255 -b

Problem solved. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to handle build user access/permissions?

All, I am looking for some guidance on how to handle permissions/access for an application build/deployment. We need to allow for software deployments via Visual Studio Team Services and a build server running on Windows, deploying to RHEL 7 servers. We would like to use a service account,... (3 Replies)
Discussion started by: hburnswell
3 Replies

2. UNIX for Dummies Questions & Answers

Adding SDK Build on Kernel Source Build

Hi, So I downloaded this kernel source and was able to build it successfully. But I want to add this SDK source code inside, can anyone help me how to do this? Note that the SDK source can be built by itself. I added the SDK in the main Makefile: init-y := init/ #added SDK... (0 Replies)
Discussion started by: h0ujun
0 Replies

3. Shell Programming and Scripting

Perl - run sub routine for list of devices

Hi, Can anyone please correct the script such that it run on all the devices in the devicelist.txt file. The problem is when the script runs it only reads the first device in the list, configures the device and exists. Script: The devicelist.txt: device.crs... (1 Reply)
Discussion started by: sureshcisco
1 Replies

4. Shell Programming and Scripting

Run SQL command for a list of devices

Hi Please help me to resolve. Question: I can run this command to change the mode of a device with id=500 as below dbc "select device mode=3 where id=500;" How can i run the same query with a file contaning n number of ids ? file1.txt 12 234 34 500 34 45 Thanks in... (3 Replies)
Discussion started by: sureshcisco
3 Replies

5. HP-UX

list of devices

Hi, I need to rediracte all the names of the devices (only disks) to a file. Thanks:confused: (3 Replies)
Discussion started by: yoavbe
3 Replies

6. UNIX for Dummies Questions & Answers

passthrough devices vs. named devices

I am having trouble understanding the difference between a passthrough device and a named device and when you would use one or the other to access equipment. As an example, we have a tape library and giving the command "camcontrol devlist" gives the following output: akx# camcontrol... (1 Reply)
Discussion started by: thumper
1 Replies
Login or Register to Ask a Question