Showing posts with label apple. Show all posts
Showing posts with label apple. Show all posts

Friday, November 08, 2013

Getting IP and MACs for hosts in a network without using nmap

Well, sometimes you need to find out which IPs in a given network are being used and what is the MAC addresses associated with them. Perhaps you want to make sure the machines are the ones that should be there (MAC spoofing notwithstanding). Or, as it happened to me before, you need to see which IPs your dhcp server have given out are actually being used. You can come up with other reasons too, even if they arenot honorable! Impress your friends! Be the life of the party!

Anyway, you can do some of this using nmap, but what if it is not available or you just want to use common Linux household commands? I have done something like this before using nslookup, but since dig is supposed to replace it, how about if we rewrite my old cold to use it? So, let's say you want to know what is in 10.0.0/24? You could do something like:

subnet=10.0.0
for i in $(seq 1 254)
  do ans=`ping -qnc 1 $subnet.$i | grep -c '100% packet loss'`
  [ "$ans" == 1 ] || echo "(+) $subnet.$i (`dig -x $subnet.$i +short` `arp -an $subnet.$i|awk '{ print $4 }'`) "
done

Or something a bit fancier, which would ask you to enter the first 3 octets of the network:

nonono() {
  printf "Enter subnet (only the first 3 octets): "
  read subnet
  for i in $(seq 1 254)
    do ans=`ping -qnc 1 $subnet.$i | grep -c '100% packet loss'`
    [ "$ans" == 1 ] || echo "(+) $subnet.$i (`dig -x $subnet.$i +short` `arp -an $subnet.$i|awk '{ print $4 }'`) "
  done
}
nonono

Here is the code in action:

raub@desktop:~$ nonono
Enter subnet (only the first 3 octets): 10.0.0
(+) 10.0.0.1 (router. 00:24:54:9s:2a:12) 
(+) 10.0.0.3 (brownie.my.domain.com. 64:6b:b3:b0:76:e1) 
(+) 10.0.0.16 (cookie.my.domain.com. 02:50:4d:c4:17:1a) 
(+) 10.0.0.18 (tomato.my.domain.com. 02:50:4d:c4:17:1a) 
(+) 10.0.0.19 (vmhost.my.domain.com. bc:5f:f4:ad:d7:8d) 
(+) 10.0.0.21 (scan.my.domain.com. c0:ff:ee:4f:96:a9) 
(+) 10.0.0.110 (pickles.my.domain.com. 00:9f:f3:46:23:90) 
(+) 10.0.0.238 (pizza.my.domain.com. c0:ff:ee:67:1c:3c) 
(+) 10.0.0.249 (desktop.my.domain.com. entries) 
raub@desktop:~$ 

Some stuff worth mentioning:

  1. Some machines have MAC beginning with c0:ff:ee. Those are VMs of mine running of vmhost; I use that so I can quickly identify them as VMs; you might want to follow the same idea if you have to deal with large amounts of VMs in server rooms.
  2. cookie and tomato have the same MAC. The reason is they are the same machine. I just configured its interface to do interface aliasing (eth0:0 and eth0:1 for instance) so one IP could be for a fileserver and another for a web server (really bad idea, which is why I thought you would like it). You can read about it in, say, here.
  3. Do note what we are calling subnet really isn't; it is just the first 3 octets in a class C network. In other words, it assumes your network is of the type a.b.c.0/24. You could change the code to handle any network provided the network IP and subnet mask; I will leave that as an exercise to you.
  4. If you want to run it in OSX, use arp -n instead of arp -an.

Tuesday, May 01, 2007

Installing OSX 10.4 without DVD player

Ok, so have here a 12" ibook that did not come with a DVD player. To its left I have the OSX 10.4 DVDs. I have to install 10.4 in the iBook. How to make them play together? Good question. Well, Apple does have a tradeup program in which you send out your 10.4 DVDs, proof of purchase, and a check of $9.95 or thereabouts and, in a few weeks, you get a 10.4 CD set. Kinda nice but this is not what we are going to do. I do not want to have to wait for a few weeks to get this taken care of. I want it now!

How to do that? Well, let's go over the different steps I tried and figure out, hopefully, why they went boink.

Boot from the built-in CD drive

Well, that one did not work out. We knew that because that is the entire reason I am writing this. This ibook has a built-in CD player, not a DVD player. If this was a desktop, chances are you could easily swap the drives. That is what I did before with a B&W Powermac G3.

Boot from an external USB DVD drive

I have an external USB dual layer DVD burner; why not use it? Well, possibly the reason is that it does not work. At least it did not work for me. I tried it and it cheerfully ignored the drive. I tried booting and holding the key sequences to boot from the cd -- I think it thought I wanted to boot from its built-in drive -- and to ignore its internal drive. Either way it did not; it kept cheerfully trying to boot from the internal hard drive.

Boot the ibook at a firewire device attached to my other ibook.

Now we are getting fancy here. From experience, I know I can make my Cube and my 14" iBook G4 to, at boot, become external hard drives that can be then connected to another machine through the firewire port. Ok, the Cube books in FW mode but right now I am having a few problems seeing its hard drive, but that is another story and I am digressing here.

External firewire drive.

Since the 12" ibook does not want to be a firewire device, what if we give it a firewire device, say, another hard drive? Well, I happen to have a USB2/Firewire case and a 10GB ATA (IDE for you old school crowd) doing nothing. So, I put the drive in the case and connect it to my 14" ibook, not to the 12" ibook just yet. There is reason behind my madness, believe it or not. So, I then boot the 14" ibook from the OSX dvd (remember this machine has a dvd player) and tell it to install tiger on the 10GB HD. After that is done, I then connect the drive to the 12" ibook and boot it. As the internal drive had no OS (I deleted it some time ago) installed, it went and found the external drive and booted from it! It seems I am on the right track.

Now let's make life more interesting. Once again I booted my 14" ibook and then connected the external drive and inserted the osx dvd. I then unmounted but not removed the firewire drive. That is an important step. I made a point to write down the firewire drive was being seen as /dev/disk2s10 and the dvd player is /dev/disk3s3. Now, there is probably a clever more Mac-like way to do this next step. But I do not know how to do it. So, I did it the unix way: I started a terminal session and entered the following command:

Mireille:~ dalek$ dd if=/dev/disk3s3 of=/dev/disk2s10
11712744+0 records in
11712744+0 records out
5996924928 bytes transferred in 11166.592623 secs (537042 bytes/sec)
Mireille:~ dalek$

I then connected the drive to the 12" ibook and rebooted. It thought the external firewire hard drive was the OSX dvd disc 1 and started the installation process! What about the disc 2? Well, I just put it in the external DVD burner and connected it to an available usb port in the 12" ibook. It happily continued installing from it.

Problem solved!

One day, when I am really bored I will try to put a dvd player in the firewire case and see if it can boot like that. In the mean time, I finished getting that 12" ibook running tiger and that is all I wanted to do for now. Next time perhaps I will have a quiet talk with a certain cube...