Submitted By: Christopher Starcher

Sends a ping packet to a remote IP address, varying the size of the packet and recording the returned values in Microsoft Excel.

PowerShell
Edit|Remove
############################################################################################################################################
# PROGRAM:  Sweep.ps1
# SYNOPSIS:  Sends a sweep of ICMP Echo Request packets from 1 to $args[1] iterations with sizes from 36 to $args[2] bytes.
# VERSION:  1.0.0.0000
# LASTMODIFIED:  2006.09.22
# SUPPORT:  Send me an email if you have any questions...
# LICENSE:  None necessary...
# COPYRIGHT:  None, I used examples to build it.
# CONTACT:  Christopher Starcher, sixtgunr@hotmail.com, send me a copy if you modify it...
# NEEDFILES:  None
# NEEDENVIRONMENT:  Windows PowerShell (Monad) http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx
# EXECUTION:  ./Sweep.ps1 127.0.0.1 $args[0] $args[1] $args[2] Ex: "./Sweep.ps1 198.133.219.25 100 18000"
############################################################################################################################################
$it = 1
$len = 36
$time = 2000
$row = 2
$avems = ""
$ip = $args[0]
$a = New-Object -comobject Excel.Application
$a.Visible = $True
$b = $a.Workbooks.Add(1)
$c = $b.Worksheets.Item(1)
$b.Sheets.Item(1).Name = "$ip Iteration $it"
$c.Columns.Item(1).ColumnWidth = 25
$c.Columns.Item(2).ColumnWidth = 25
$c.Cells.Item(1,1) = "Packet Size(Bytes)"
$c.Cells.Item(1,2) = "RTT Time(ms)"
do
	{
	do
		{
		$average = ping -n 1 -l $len -w $time $args[0] | findstr "Average"
		$c.Cells.Item($row,1) = $len
		$c.Cells.Item($row,2).select() | findstr "False"
		$avems = $average.split(",")
		$t1 = $avems[2].Replace(" Average = ", "")
		$t2 = $t1.Replace("ms", "")
		$c.Cells.Item($row,2) = $t2
		$len = ($len + 10)
		$row++
		}
	while ($len -lt $args[2])
	$it++
	$len = 36
	$row = 2
	if ($it -gt $args[1])
		{
		$b.SaveAs("C:\Output\Ping.$ip.xls") | findstr "False"
		$a.Quit()
		}
	Else
		{
		$c = $b.Worksheets.Add()
		$b.Sheets.Item(1).Name = "$ip Iteration $it"
		$c.Columns.Item(1).ColumnWidth = 25
		$c.Columns.Item(2).ColumnWidth = 25
		$c.Cells.Item(1,1) = "Packet Size(Bytes)"
		$c.Cells.Item(1,2) = "RTT Time(ms)"
		}
	}
while ($it -le $args[1])