Skip to content

Instantly share code, notes, and snippets.

@gigaherz
Created September 6, 2014 15:10
Show Gist options
  • Save gigaherz/94050d6e2b76e9b7ba3a to your computer and use it in GitHub Desktop.
Save gigaherz/94050d6e2b76e9b7ba3a to your computer and use it in GitHub Desktop.
function SetupForm{
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null;
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null;
$form = New-Object System.Windows.Forms.Form;
$dgv = New-Object System.Windows.Forms.DataGridView;
$form.Text = "TCP Connection Status";
$form.Name = "form";
$form.Controls.Add($dgv);
$dgv.Width = $form.Width - 10;
$dgv.Height = $form.Height
$dgv.Anchor = [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Top
$timer = New-Object System.Windows.Forms.Timer;
$timer.Interval = 1000;
$timer.add_Tick({
$result = [System.Net.NetworkInformation.IpGlobalProperties]::GetIPGlobalProperties().GetActiveTcpConnections();
$dgv.Datasource = $result;
});
$timer.Enabled = $TRUE;
$form.Visible = $TRUE;
[System.Windows.Forms.Application]::Run($form);
}
SetupForm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment