0

We have numerous laptops here which have two adjacent DHCP reservations, one for the wired interface, and the next for the wireless. This allows simpler firewall rules by using (e.g.) /28 subnets for all NICs on all laptops in given department.

NSLOOKUP properly returns both interfaces when querying a machine:

$ auk

Server: ourcompany-dc3.ourinternaldomain.local

Address: 192.168.28.9

Name: auk.ourinternaldomain.local

Addresses: 192.168.28.79 192.168.28.78

I'm looking for a single ping command that will try both NICs to see which one is connected. And it should be by name, not address.

However, if I ping by name, it only tries one of the machine's NICs, which only works half the time (depending on which way the user is currently connected). Obviously, I could do the NSLOOKUP first, and then try pinging both addresses, but this is what I am trying to avoid: I want to simply ping a name to see how a specific machine is attached.

Is there a ping (or dig, or anything else, for that matter) option that will automatically try all a host's NICs as found by a DNS lookup?

PS: I do know how to write a script to do this, but I'd have to drag the script around to every machine I might be using (or put it on a share), which is more trouble than it's worth.

  • 2
    In my opinion, you're creating the problem by having both IPs in DNS with the same name. Nearly every DHCP server should have a way to handle dynamic DNS updates at this point, if you used that your problem is solved. I would put the existing IPs in DNS with a unique hostname, like 'machine-w' and 'machine-wl' (wired / wireless). Let DHCP update the main record when it gives out it's lease. –  Aug 16 '17 at 23:04
  • Thanks for your suggestion. In fact we do use this strategy a couple of smaller locations, but it is entirely workable here because we often want to refer to a machine without respect to which path is used to reach it (i.e. by name only). – evenmoreconfused Aug 18 '17 at 17:03
  • Sorry, I meant "... it is NOT entirely workable here because ...", but I can't edit it any more. We do use dynamic DNS here, and it works, but the old record sticks around even after the new one connects (which is right, as the first connection might not be disconnected). I don't believe there is a way to remove a dynamic DNS record when the connection dies -- you have to wait for it to age out. – evenmoreconfused Aug 18 '17 at 17:26

3 Answers3

0

I have about 60 computers in my house and keeping them in line is quite the bugger when only half are on Static IP's (for good reason too but none to worry!). I do have a list written down of what the static ones are but then I forget what services (servers/software with open ports to the machine) are running on the individual machines! Webmin certainly takes care of moderating like any good CPanel program. But even better is an app called Fing on the iOS App Store and Google Play Store. Located here, the app is free and will do a better job than NMap or "AngryIPScanner" or "NetSniffer" etc will ever do combined. It is super quick too! NMap can scan 5 computers in the time it takes Fing to do 30.

It works on any network I've thrown at it including the "ShawOpen" networks you'll find in Canada which have hundreds of people connected at a time, talk about a way to spot vulnerabilities! Have lots of fun!

Tmanok
  • 197
  • 2
  • 13
  • 1
    Thanks, I will look at Fing. We use WhoIsOnMyWifi for this, which I think is great, but Fing might be better. However, it's not intended for the question I asked, which is how to make ping test multiple addresses. – evenmoreconfused Aug 18 '17 at 17:06
  • Sorry EMC, "NMap" or "AngryIPScanner" is how you ping multiple addresses as mentioned above. NMap is a terminal software and Fing also works on windows CMD and Terminal as a hidden desktop software. – Tmanok Aug 18 '17 at 21:05
  • I think there's some confusion here. I know nmap well and use it often, but haven't ever seen an option to have it ping all a host's addresses when given a host name -- only lots of options to scan ranges of addresses at various levels of aggressiveness. In any case, all I need is to know which NICs on the host are up; nmap is admittedly very flexible but by default, anyway, creates a whole bunch of output. I don't know AngryIPScanner but will check it out too. – evenmoreconfused Aug 19 '17 at 21:22
  • -- deleted as I can't see how to put CRs in a comment, without which I can't put a sensible code block -- – evenmoreconfused Aug 19 '17 at 21:23
  • Trying to be more clear, I want a command line utility which takes a hostname as its parameter, and it outputs a line for each DNS-registered IP address, and a status for that address, such as "Up, 3ms ping" or "No response". NSLOOKUP doesn't fit the bill (it gives all the addresses, but no status), and neither does PING (it gives an address and the status, but only for the first address). – evenmoreconfused Aug 19 '17 at 21:32
  • So you want a performance / statistic software. Again: NMap. Please enter your IP range into this code: nmap -sP -R 192.168.0.1-254 and you'll find the Pings of all of those IPs. sP means ping, R means recursive. You could probably forget the R. I really do suggest you look into suggested software but it's my fault for not pointing it out. – Tmanok Aug 20 '17 at 18:15
  • As I've mentioned above, this is not at all what I want. I know nmap well and use it all the time. Nmap will list all the machines in the specified range, provided they are up, with Ping results and optionally things like OS detection. What I want is to enter a machine name, get a list of its DNS -registered NIC addresses (not UP addresses), along with whether that NIC is up or down. Also I don't want any other machines listed -- just the host I asked for. Look at the first suggestion by Cedric Knight above -- it's exactly what I want! – evenmoreconfused Aug 21 '17 at 23:14
  • Also notice that in the example he gives (bbc.co.uk), the two addresses returned by nslookup are in two different /16 subnets. If I had to do that with nmap it would A) take all day, B) produce hundreds of thousands of lines of output, and C) likely get us banned by our ISP. – evenmoreconfused Aug 21 '17 at 23:23
0

A better answer, separate from the previous answer is to use the system. You can do this with Linux & Mac OS, or emulate either on Windows:

echo $(seq 254) | xargs -P255 -I% -d" " ping -W 1 -c 1 192.168.0.% | grep -E "[0-1].*?:"

It will output the following:

64 bytes from 192.168.0.16: icmp_seq=1 ttl=64 time=0.019 ms
64 bytes from 192.168.0.12: icmp_seq=1 ttl=64 time=1.78 ms
64 bytes from 192.168.0.21: icmp_seq=1 ttl=64 time=2.43 ms
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=1.97 ms
64 bytes from 192.168.0.11: icmp_seq=1 ttl=64 time=619 ms

I sourced this answer from another on Stack Networking

Tmanok
  • 197
  • 2
  • 13
  • Ok, thank you for this, but I can't see where to put the host name in the above, nor where it says which of the NICs belong to the host I'm actually interested in. Am I missing something? – evenmoreconfused Aug 21 '17 at 19:10
0
  1. There's no switch to check all lookup results in any ping utility I know. Most software that takes a hostname as a parameter just looks it up in gethostbyname() and takes the first result in order to connect.

So how about a one liner? It sounds like you have nslookup installed, but it would be similar for the host command.

p() { for i in `nslookup $1 | sed 's/^Address: //;t;d'` ; do ping -q -c2 $i ; done }

produces

$ p www.bbc.co.uk
PING 212.58.244.67 (212.58.244.67) 56(84) bytes of data.

--- 212.58.244.67 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 21.908/22.214/22.520/0.306 ms
PING 212.58.246.91 (212.58.246.91) 56(84) bytes of data.

--- 212.58.246.91 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 24.484/24.876/25.269/0.423 ms
  1. Someone mentioned nmap. If all your IP addresses are adjacent, here's a trick that seems to work:

    nmap -sn auk.ourinternaldomain.local/31

Or /30 or bigger if they're not aligned.

$ nmap -sn dns.google.com/31

Starting Nmap 6.40 ( http://nmap.org ) at 2017-08-20 20:46 BST
Nmap scan report for dns.google.com (216.58.214.14)
Host is up (0.031s latency).
rDNS record for 216.58.214.14: lhr26s05-in-f14.1e100.net
Nmap scan report for lhr26s05-in-f15.1e100.net (216.58.214.15)
Host is up (0.029s latency).
Nmap done: 2 IP addresses (2 hosts up) scanned in 0.10 seconds
  1. I notice NirSoft produces a freeware Windows GUI utility called PingInfoView
Cedric Knight
  • 1,108
  • 7
  • 20
  • 1
    These are great, thanks. The first one does exactly what I want. The second does something similar but depends on nmap being on the box and also somewhat on proper /31 subnets (which is mostly, but not always, the case here). The third is definitely not what I'm looking for, I already have half a dozen GUI solutions to this. I need something that will run from any CLI window I happen to have open (as I can with ping). About half our systems here are Windows, but I can write an equivalent powershell cmdlet given your first suggestion and put it somewhere that's available wherever I am. – evenmoreconfused Aug 21 '17 at 19:21
  • Glad it helps. You might want to answer your own question when you've tested your PowerShell cmdlet. – Cedric Knight Aug 21 '17 at 20:39