Scanning a range of IPs

bwana

MyBroadband
Super Moderator
Joined
Feb 23, 2005
Messages
98,231
Reaction score
38,653
Location
Plz
Any idea how I can scan a range of IP addresses for machines with a specific port open? Command line is fine.

We've been having regular power outages at night and it's been resetting my office machine's IP address. It's generally in the same range when the adsl comes back online but its a pain having to drive over to office to get it.

I'm local only on that machine and the ISP doesn't offer any sort of dyndns service.
 
nmap allows you to do that, but I don't see it included in OSX. Download it here. After running the installer, there will be a commandline util at /usr/local/bin/nmap.

Then run nmap on the range. I assume you know which port you're looking for. Suppose we're looking for port 80 on the 196.25.15.0-255 range, type:

Code:
sudo /usr/local/bin/nmap -p80 196.25.15.0/24

If you're running little snitch, it's gonna bitch at you :)
 
Any idea how I can scan a range of IP addresses for machines with a specific port open? Command line is fine.

We've been having regular power outages at night and it's been resetting my office machine's IP address. It's generally in the same range when the adsl comes back online but its a pain having to drive over to office to get it.

I'm local only on that machine and the ISP doesn't offer any sort of dyndns service.

@ bwana - depending on the model of router (or DHCP server) it is possible to hardcode a dynamic IP to a specific network card (or MAC address).

Assuming it is windows, you can run

Code:
ipconfig /all

on the command line to get the NIC's MAC address, as shown below :

Code:
Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : National Semiconductor DP83815-Based
 PCI Fast Ethernet Adapter
        Physical Address. . . . . . . . . : 00-03-0D-11-F3-51
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.xx.xx.xx
        Subnet Mask . . . . . . . . . . . : 255.xx.xx.xx
        Default Gateway . . . . . . . . . : 192.xx.xx.xx
        DHCP Server . . . . . . . . . . . : 192.xx.xx.xx
        DNS Servers . . . . . . . . . . . : 192.xx.xx.xx
        Lease Obtained. . . . . . . . . . : 16 November 2008 08:56:50 AM
        Lease Expires . . . . . . . . . . : 16 November 2008 09:56:50 AM

The physical address of 00-03-0D-11-F3-51 is your NIC's MAC address.

You can then enter (at the DHCP management console) this MAC address and assign a static IP to it - which the machine will always be assigned.

You can PM me for more information if needed.

Regards

Libs
 
nmap allows you to do that, but I don't see it included in OSX. Download it here. After running the installer, there will be a commandline util at /usr/local/bin/nmap.

Then run nmap on the range. I assume you know which port you're looking for. Suppose we're looking for port 80 on the 196.25.15.0-255 range, type:

Code:
sudo /usr/local/bin/nmap -p80 196.25.15.0/24

If you're running little snitch, it's gonna bitch at you :)
Thanks - I'll give it a try

@ bwana - depending on the model of router (or DHCP server) it is possible to hardcode a dynamic IP to a specific network card (or MAC address).

Assuming it is windows, you can run

Code:
ipconfig /all

on the command line to get the NIC's MAC address, as shown below :

Code:
Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : National Semiconductor DP83815-Based
 PCI Fast Ethernet Adapter
        Physical Address. . . . . . . . . : 00-03-0D-11-F3-51
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.xx.xx.xx
        Subnet Mask . . . . . . . . . . . : 255.xx.xx.xx
        Default Gateway . . . . . . . . . : 192.xx.xx.xx
        DHCP Server . . . . . . . . . . . : 192.xx.xx.xx
        DNS Servers . . . . . . . . . . . : 192.xx.xx.xx
        Lease Obtained. . . . . . . . . . : 16 November 2008 08:56:50 AM
        Lease Expires . . . . . . . . . . : 16 November 2008 09:56:50 AM

The physical address of 00-03-0D-11-F3-51 is your NIC's MAC address.

You can then enter (at the DHCP management console) this MAC address and assign a static IP to it - which the machine will always be assigned.

You can PM me for more information if needed.

Regards

Libs
How will this help me hunt down my needle in the haystack?

If that sounds hard (which it does) you could try AngryIP scanner, works great.
Thanks also.

A web based port scanner: http://www.t1shopper.com/tools/port-scanner/
A pretty ok Windoze one: http://www.radmin.com/products/utilities/portscanner.php
Bwana, you have to setup DynamicDNS on this machine though.
I'd love to but its local only bandwidth so it doesnt register - is there a local DynDNS?
 
bwana, are you talking about the computer's IP or the ADSL IP? If it's the computer itself, The_Librarian's suggestion might work (forget the windows blabbering :)) Most routers allow you to set up DHCP reservations, i.e. force the DHCP server to always assign the same IP to a request coming from a specific MAC address.

I assume the work machine is a Mac too? You can find the MAC address by typing 'ifconfig' in the terminal:

Code:
$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
        inet 127.0.0.1 netmask 0xff000000 
        inet6 ::1 prefixlen 128 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
[B]en0[/B]: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        [U]ether 00:1b:63:ae:c5:ee[/U] 
        media: autoselect status: inactive
        supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control> none
[B]en1[/B]: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet 192.168.1.122 netmask 0xffffff00 broadcast 192.168.1.255
        inet6 fe80::21d:4fff:fefd:482b%en1 prefixlen 64 scopeid 0x5 
        [U]ether 00:1d:4f:fd:48:2b[/U] 
        media: autoselect status: active
        supported media: autoselect
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 2030
        lladdr 00:1d:4f:ff:fe:7b:db:66 
        media: autoselect <full-duplex> status: inactive
        supported media: autoselect <full-duplex>
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet 192.168.212.1 netmask 0xffffff00 broadcast 192.168.212.255
        ether 00:50:56:c0:00:08 
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet 192.168.63.1 netmask 0xffffff00 broadcast 192.168.63.255
        ether 00:50:56:c0:00:01

In my case en0 is wired and en1 is wireless. 'ether' is the MAC address.

Your other option is to just not use DHCP for that machine. Give it a static IP in the same range, and make sure the DHCP server's range excludes it. That way it never changes, and you don't get IP conflicts.
 
ok - I'm here - the other computer is in my office but the remote IP address has changed after a reset.

I've got a few specific ports open on the router and the IP is usually in a certain range but I cant be bothered to ping each IP address in that range individually.

I'm also too lazy to get in my car, drive to the office, and check the current IP.

I want to ping a range of IP addresses for the open port (on the remote computer) in order to narrow down the possibilities.
 
Then do exactly what I said in my first post. Or give me the range (pm if you want) and I'll scan and send you the output.
 
Then do exactly what I said in my first post. Or give me the range (pm if you want) and I'll scan and send you the output.
That's exactly what I am doing - nmap also came with a GUI for the terminally challenged. :)
 
LOL OK. There is one downside to this. If your firewall on the other side is smart enough, it will detect a port scan and block you. That's why I suggest scanning for only one port.
 
You could run a cron on your office machine to let you know when the IP changes, depending on your setup.
 
LOL OK. There is one downside to this. If your firewall on the other side is smart enough, it will detect a port scan and block you. That's why I suggest scanning for only one port.
It hasnt worked so far for me but perhaps the router is in 'stealth' mode (or whatever they call it) - I'll have to check that in the morning.
You could run a cron on your office machine to let you know when the IP changes, depending on your setup.
I wouldnt know where to begin. :)

I do however have another plan in the meantime - I'm going to set up an email rule to auto reply to any email that matches certain criteria and use the IP in the header info.
 
I do however have another plan in the meantime - I'm going to set up an email rule to auto reply to any email that matches certain criteria and use the IP in the header info.

Well that's all you need. I have written a script at home that checks the IP address and adds it into a database on a server somewhere. So I can log in and check the last entry, so I know the address. This hooks into the linux start-up scripts (this is my work machine), so I'm not sure how to go about doing the same thing in OSX - I'm not familiar with the way network devices are activated/deactivated. I guess applescript will probably help, but again, I'm not familiar with it.
 
The code for getting your external IP in Applescript.

set Ext_IP to word 25 of (do shell script "curl checkip.dyndns.org")
try
set Int_IP to (do shell script "ipconfig getifaddr en0")
on error -- box is not wired, try wireless
set Int_IP to (do shell script "ipconfig getifaddr en1")
end try
{Ext_IP, Int_IP}
 
The code for getting your external IP in Applescript.

set Ext_IP to word 25 of (do shell script "curl checkip.dyndns.org")
try
set Int_IP to (do shell script "ipconfig getifaddr en0")
on error -- box is not wired, try wireless
set Int_IP to (do shell script "ipconfig getifaddr en1")
end try
{Ext_IP, Int_IP}
If this step is important then the scrip wont work for me but someone else might find it useful. :)
 
I have a customized dynamic IP server setup here. Basically I used the script from dyndns.org... and set it so it updates a local server so I can control my own domains and include encryption. I could share the dyndns script is anyone wanted:P
 
Top
Sign up to the MyBroadband newsletter
X