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 ( Read more... )

Leave a comment

Comments 5

pat_trick May 17 2008, 06:46:03 UTC
that's an awesome little script!

now modify it to run a ping test on each of those IP addresses, outputting the results to a file, and then concatenating each output to the tail end of said file. :D

Reply

wizzrobe May 17 2008, 14:14:28 UTC
Pat, you must be telepathic. This is just one part of a big script I want to build, right now I'm figuring out one component at a time. Here's what I want it to do eventually ( ... )

Reply

wizzrobe May 18 2008, 00:35:28 UTC
I think I've got it:

$3rdOctet=232
while ($3rdOctet -lt 240)
{for ($4thOctet=0; $4thOctet -lt 256; $4thOctet++)
{if ("$3rdOctet.$4thOctet" -eq "239.255")
{write-output "Done!"}
elseif ("$3rdOctet.$4thOctet" -eq "232.0")
{write-output "Subnet prefix skipped!" | out-null}
else
{ping -n 1 "10.198.$3rdOctet.$4thOctet" | out-file c:\temp.txt;
$temp = get-content c:\temp.txt;
if ($temp[6] -match "Reply from 10.198.$3rdOctet.$4thOctet")
{$pingResponse = "Yes"}
else {$pingResponse = "No"};
out-file -append c:\IPs.txt -inputobject "10.198.$3rdOctet.$4thOctet, $pingResponse"}};
if ($4thOctet=255)
{$3rdOctet++};
if ($4thOctet=255)
{$4thOctet=0}
}

Reply

wizzrobe May 18 2008, 00:37:34 UTC
And this was formatted nicely, but LJ hosed it.

Reply


Leave a comment

Up