How to list a range of IP addresses with the Linux seq command

Ever needed to convert IP addresses that someone has written down into a list?
eg: 10.0.0.47 to 52 and 192.168.243.5 to 12

Try seq, as follows:

$seq -f "10.0.0.%g" 3 6
10.0.0.3
10.0.0.4
10.0.0.5
10.0.0.6

Or for my example:

$seq -f "10.0.0.%g" 47 52 ; seq -f "192.168.243.%g" 5 12
10.0.0.47
10.0.0.48
10.0.0.49
10.0.0.50
10.0.0.51
10.0.0.52
192.168.243.5
192.168.243.6
192.168.243.7
192.168.243.8
192.168.243.9
192.168.243.10
192.168.243.11
192.168.243.12

You could then redirect the output too:

$seq -f "10.0.0.%g" 47 52 ; seq -f "192.168.243.%g" 5 12 > ips.txt

Hope this is useful.

(Visited 620 times, 1 visits today)
Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.