0

How can I use shell scripting to append a range of IPs to a file?

mailq
  • 17,023
  • 2
  • 37
  • 69
neotobe
  • 11
  • 1
    Yes you can. `echo "192.168.0.1/24" >> /path/to/file`. – mailq Nov 10 '11 at 19:13
  • 1
    Oh, or do you need it that way? `echo 192.168.0.{0..255} >> /path/to/file` – mailq Nov 10 '11 at 19:25
  • 5
    Please, [classes don't exist from eons](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing). You are referring to a /24. – ata Nov 10 '11 at 19:30

1 Answers1

8

Try something like:

#!/bin/bash

for i in {0..255}
do
    echo 192.168.0.$i >>outfile.txt
done

The >> operator is used to append to a file.

jscott
  • 24,484
  • 8
  • 79
  • 100
user9517
  • 115,471
  • 20
  • 215
  • 297
  • Thank you so much!! ps.: I know I should have found it out by myself, but I know next to nothing about shell scripting, and was (am) dead tired after adding the whole /24 range by hand in a web console (Apache/Tomcat). I'll try not to ask stupid questions next time! – neotobe Nov 10 '11 at 22:07