I am unreasonably proud of myself

May 16, 2008 19:01

I wrote a PowerShell script! :D It's super exciting - it makes a list of all the IPs in an IPv4 subnet and writes them to a text file! :D (I'm sure this accomplishment would not impress anyone with any non-zero amount of expertise in scripting, but this is my first time writing a script, gotta start with the small stuff.) The script can easily be modified to produce a list of IPs for any subnet with 16 or more fixed bits. As set up below, it writes a list of all the IPs in the subnet 10.198.232.0/21 to the file C:\IPs.txt:

$3rdOctet=232
while ($3rdOctet -lt 240)
   {for ($4thOctet=0; $4thOctet -lt 256; $4thOctet++)
      {out-file -append -filePath c:\IPs.txt -inputobject "10.198.$3rdOctet.$4thOctet"};
      if ($4thOctet=255)
         {$3rdOctet++};
      if ($4thOctet=255)
         {$4thOctet=0}
   }
Previous post Next post
Up