Running a Continuous Ping that doesn’t stop (on Windows)

If you open a command prompt in Windows, and do a ping test, you’ll notice that it will only perform four pings and then stop.  This is OK if you want to do a quick test, but, what if you want to perform a continuous ping that keeps pinging?

Well, we have the -t option!

ping -t <hostname or IP address>

This will now ping continuously until you stop it – by pressing Ctrl and C or closing the window!

Add Line Numbers to grep Output

Often you will grep for certain strings in a text file, but need to find which line it’s on within that file. On a standard grep output, you will see the output, but have no idea which line the string has been found on.

grep has an option, -n, which resolves that.

As an example, imagine we’re grep’ing a text file for the word “line”:

$ grep "line" example-file.txt
This is line 1
This is line 3
This is line 5
This is line 7
line
Another line
And Another line

We have found every instance of “line” in example-file.txt, however, if we wanted to find these quickly in a text editor, we wouldn’t know which line to go to.  Therefore, we add the -n option:

$ grep -n "line" example-file.txt
1:This is line 1
3:This is line 3
5:This is line 5
7:This is line 7
9:line
10:Another line
11:And Another line

Now, we have the line number as part of the output, and we can instantly jump to that line in our favourite text editor. (Which is Vim, right?)

Add Line Numbers to “cat” Output

cat can be used to print the contents of a file in a Terminal, and it’s often useful to number each line of the output (including empty lines).

Adding line numbers is as simple as adding the -n switch to the command:

cat -n filename.txt

Example Output, with -n switch:

$ cat -n filename.txt

1 Line 1
2 Line 2
3 Line 3
4 Line 4
5 Line 5

Example Output, without -n:

$ cat filename.txt

Line 1
Line 2
Line 3
Line 4
Line 5

 

“Ping Hostname” Returning an IPv6 Address Instead of IPv4? (Windows)

On Windows based PCs and Servers, and where IPv6 is enabled on one of the network adapters, you may find that when you do a:

ping name-of-host

… you get an IPv6 address returned in the results.  But what if you want to test IPv4 connectivity?  You can add a -4 switch to the ping command to force it to use IPv4 as follows:

ping -4 name-of-host

Ping will now ping the IPv4 address as opposed to the IPv6.

It’s worth noting, that if you do want to test for IPv6 connectivity, you can add a -6 switch to force that:

ping -6 name-of-host

Using grep and Ignoring Case (Case Insensitive grep)

grep is a great way to find phrases, words, and characters in text.  One of the biggest stumbling blocks is case – is the word “Hello”, “hello”, “HELLO”, or even “HeLLo”?  All of these are different, and a “grep “Hello”” would only find lines containing the first “Hello” example.

You can, however, exclude case from a grep to make it not case sensitive – simply add -i:

grep -i “Hello” textfile.txt

Alternatively, you could use it in conjunction with cat and tac (Reverse Cat)

cat textfile.txt | grep -i “Hello”

The above will find all lines containing “Hello” in textfile.txt, whether it’s “Hello”, “HELLO”, HElLO”, etc, making it much easier to find instances of “Hello” if you don’t really need to care about case.

 

(Read the article on Wikipedia about Case Sensitivity..)

CIDR, Subnet Masks, and Usable IP Addresses Quick Reference Guide (Cheat Sheet)

A quick reference Subnet and CIDR guide.

What’s a /28?  How many IPs do I get to use with a /26?  Well, see the table below!
Usable IPs is the Total IPs minus the Network and Broadcast IPs.

 

CIDR

Subnet Mask

Total IPs

Usable IPs

/32255.255.255.25511
/31255.255.255.25420
/30255.255.255.25242
/29255.255.255.24886
/28255.255.255.2401614
/27255.255.255.2243230
/26255.255.255.1926462
/25255.255.255.128128126
/24255.255.255.0256254
/23255.255.254.0512510
/22255.255.252.010241022
/21255.255.248.020482046
/20255.255.240.040964094
/19255.255.224.081928190
/18255.255.192.016,38416,382
/17255.255.128.032,76832,766
/16255.255.0.065,53665,534
/15255.254.0.0131,072131,070
/14255.252.0.0262,144262,142
/13255.248.0.0524,288524,286
/12255.240.0.01,048,5761,048,574
/11255.224.0.02,097,1522,097,150
/10255.192.0.04,194,3044,194,302
/9255.128.0.08,388,6088,388,606
/8255.0.0.016,777,21616,777,214
/7254.0.0.033,554,43233,554,430
/6252.0.0.067,108,86467,108,862
/5248.0.0.0134,217,728134,217,726
/4240.0.0.0268,435,456268,435,454
/3224.0.0.0536,870,912536,870,910
/2192.0.0.01,073,741,8241,073,741,822
/1128.0.0.02,147,483,6482,147,483,646
/00.0.0.04,294,967,2964,294,967,294


Using dig to Query a Specific DNS Server (Name Server) Directly (Linux, BSD, OSX)

There may be occasions when you wish to query a DNS server directly.  I often do it before changing DNS servers for a domain; I’ll setup the new records on the new DNS servers, and then query them directly to ensure they are returning the correct records.

I recommend that anyone running DNS services for any domain looks into these commands – they’re very useful, especially when you’re making changes.

dig has a feature which allows you to specify a name server along with the record you want to query.

For example, one of the DNS servers for droptips.com is “ns.123-reg.co.uk”.  We can query this server directly, for the www record by doing the following:

$ dig droptips.com @ns.123-reg.co.uk

You’ll get some output with a section titled Answer Section:

;; ANSWER SECTION:
 droptips.com.       86400   IN      A       89.238.134.5

This details the result (89.238.134.5) and also the TTL for the record (in seconds).  The TTL is important, as this is how long caching DNS servers should cache the result for – in this case, 86400 seconds which is 1 day. Using this command to find out a TTL value for a particular record is also quite useful, especially if you’re investigating DNS cache issues.

You can also do the same to check other records such as MX records, by simpling adding the record type to the command.  For example, to get the MX records ns1.google.com is reporting for google.co.uk:

$ dig MX google.co.uk @ns1.google.com

… with the results:

;; ANSWER SECTION:
 google.co.uk.           10800   IN      MX      10 google.com.s9a2.psmtp.com.
 google.co.uk.           10800   IN      MX      10 google.com.s9b1.psmtp.com.
 google.co.uk.           10800   IN      MX      10 google.com.s9b2.psmtp.com.
 google.co.uk.           10800   IN      MX      10 google.com.s9a1.psmtp.com.

You can see in this instance, that the TTL is 10800 seconds which is 3 hours, and all MX records have the same priority level of 10.

iPhone Data Usage: My Average Monthly Data Usage

Here in the UK, mobile operators include different amounts of data with the iPhone data tarrifs – some even offer unlimited (with fair use making them not unlimited at all).  Check the terms very closely, to know exactly how much data is included with your tariff on a monthly basis.

I bought an iPhone 3GS just under a year ago (20th June 2009) and my data usage in that time has been just 908MB, sent and received.  That’s not much.  I do use WiFi when at home, though.

I have an Exchange push account (with quite a bit of mail flow), random other push apps, I use the browser quite a bit when out and about, I use the maps, and I send a fair few e-mails, often including pictures etc.  I’d say my use is fairly typical.

My average data use (none-WiFi data) a month is 75MB.  So, even if you doubled the use, it’s still only 150MB.  You could say you use data on your iPhone five times as much as me, and it’s still only 375MB a month!

The allowances are often quite high (for a phone) – I’d be surprised if you hit the limit (at time of this post) offered by the mobile companies, certainly in the UK, unless you’re tethering it and using it as a modem, or constantly streaming video such as YouTube etc.

What’s your data usage?  Let me know in comments below!

iPhone Data Usage
iPhone Data Usage

When Did You Last Reboot Your Microsoft Windows 7 Machine? (Check Uptime)

Finding out when you last rebooted your Windows 7 machine can be completed using the “systeminfo” command.

Open a Command Prompt by going to Start and opening “cmd”. You will then be presented with a command prompt window, where you need to type the systeminfo command below:

C:\> systeminfo | find "System Boot Time"
System Boot Time:          05/06/2010, 12:55:07

You will then be shown the date and time the server was booted (as seen in the example above).

You can just run “systeminfo” on it’s own (with no ‘| find “System Boot Time”‘), and you will be presented with a lot of other information such as Hotfixes, Network Connections, etc.