Wednesday, May 28, 2014

Print out all the IPs in a Subnet Using Linux Command

In my particular case, I need to print out every IPs in a subnet, I used 'nmap' command together with option '-sL', it will list the IPs in the subnet, but not actually do any scan. Here is the first 5 lines and last 5 lines of the output. I checked a /22 subnet.
# nmap -n  -sL 10.188.75.0/22 | head -5

Starting Nmap 5.51 ( http://nmap.org ) at 2014-05-28 06:39 EDT
Nmap scan report for 10.188.72.0
Nmap scan report for 10.188.72.1
Nmap scan report for 10.188.72.2

# nmap -n  -sL 10.188.75.0/22 | tail -5
Nmap scan report for 10.188.75.252
Nmap scan report for 10.188.75.253
Nmap scan report for 10.188.75.254
Nmap scan report for 10.188.75.255
Nmap done: 1024 IP addresses (0 hosts up) scanned in 0.01 seconds
 Since every line I interested has string "Nmap scan report for", I use this to select them, and also delete the first line (network itself) and last line (broadcast address). Unfortunately, there are total 1022 IPs in a /22 subnet, I don't want to display them all, so I list the first 5 IPs, and last 5 IPs.
# nmap -n  -sL 10.188.75.0/22 | sed -n '/Nmap scan report for /s/Nmap scan report for //gp' | sed '$d' | sed '1d' | head -5
10.188.72.1
10.188.72.2
10.188.72.3
10.188.72.4
10.188.72.5

# nmap -n  -sL 10.188.75.0/22 | sed -n '/Nmap scan report for /s/Nmap scan report for //gp' | sed '$d' | sed '1d' | tail -5
10.188.75.250
10.188.75.251
10.188.75.252
10.188.75.253
10.188.75.254

Sunday, March 16, 2014

Amazing intelligent Google maps

I have to say that I'm really impressed by the amazing intelligence of Google maps. Here is the story I always told to my friends so they might also like to use Google maps.

One evening, there was a natural gas leak right before the major entries of high way 78. I came from southwest, driving toward northeast. A lot of police cars blocked the road due to the natural gas leak incident. I put on Google maps after stuck in the traffic for a while (that's my daily commute, I don't need any GPS if everything was normal), and Google maps detoured me to a small road, and directed me to pass the middle barrier as shown in the green line in attached screen shot. The amazing things were:

1. This route was not allowed in a normal condition due to the heave traffic in both directions.
2. The gap between the middle barrier and Police cars were only about 100 feet.

I don't know how Google maps figured out that incredible since the incidents probably only happened 2 hours ago. One I put the Google maps on, it only took me 20 minutes to pass this point. I knew a lot of my friends were stuck there for 4 hours even some of them tried to use GPS. No any other GPS could be so intelligence as Google maps.