Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Historically, Microsoft hasn't bothered to ship NT with many
- useful network debugging tools. It's still best
- to use Russinovich's Syinternals utility psping64.exe if possible.
- It's a way better tool and isn't limited to 3 parameters. Download:
- https://learn.microsoft.com/en-us/sysinternals/downloads/psping.
- Likewise, Nir Sofer has written an excellent library of Windows
- troubleshooting software available at http://www.nirsoft.net/.
- Unfortunately, his software tends to throw Win Defender Alerts.
- Feel free to use, change, delete, or distribute this script.
- .DESCRIPTION
- A script that allows user to simulate port-specific
- UDP traffic, targeted at IPv4-specific end-stations.
- It can be executed interactively or at the shell using params below.
- .NOTES
- File Name : Send-UDP-Datagram.ps1
- Author : Mark Driscoll
- Version : 1.0
- Prerequisite : PowerShell v5.1
- Copyleft 2023 : Acronis Intl. GmbH
- Date Created : 08-08-2023
- .EXAMPLE
- load the script into your environment, then call it by its name and use the params listed
- above the function: ---GatwayIPv4 <int> --Port <int> --Message <string>
- .USAGE
- Send-UdpDatagram -EndPoint <REMOTE_GW_IP> -Port <UDP_PORT> -Message "test.mymetric:0|c"
- .Link
- [1] https://en.wikipedia.org/wiki/Berkeley_Software_Distribution#cite_note-15
- #>
- param(
- [Parameter()]
- [string]$GatewayIPv4,
- [Parameter()]
- [int]$Port,
- [Parameter()]
- [string]$Message = "test.metric:0|c"
- )
- function Send-UdpDatagram
- {
- Param ([string] $EndPoint,
- [int] $Port,
- [string] $Message)
- $IP = [System.Net.Dns]::GetHostAddresses($EndPoint)
- $Address = [System.Net.IPAddress]::Parse($IP)
- $EndPoints = New-Object System.Net.IPEndPoint($Address, $Port)
- $Socket = New-Object System.Net.Sockets.UDPClient
- $EncodedText = [Text.Encoding]::ASCII.GetBytes($Message)
- $SendMessage = $Socket.Send($EncodedText, $EncodedText.Length, $EndPoints)
- $Socket.Close()
- Write-Host $SendMessage
- Write-Host "Sent message: '$Message' to ${$EndPoint}:$Port"
- }
- if (-not $GatewayIPv4) {
- $GatewayIPv4 = Read-Host -Prompt "Enter the target IP Address"
- }
- if (-not $Port) {
- $Port = Read-Host -Prompt "Enter the UDP Port"
- }
- if (-not $Message) {
- $Message = Read-Host -Prompt "Enter the Message to send (default: test.metric:0|c)"
- }
- if ($GatewayIPv4 -and $Port -and $Message) {
- Write-Host "All parameters are pre-defined. Exiting the loop."
- break
- }
- $endTime = (Get-Date).AddSeconds(600)
- # Continue looping until finished capturing packets; else, timer terminates after 300s
- while ((Get-Date) -lt $endTime)
- {
- Send-UdpDatagram -EndPoint $GatewayIPv4 -Port $Port -Message $Message
- Start-Sleep -Seconds 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement