Skip to content

Instantly share code, notes, and snippets.

@akechi-haruka
Created December 9, 2024 13:09
Show Gist options
  • Select an option

  • Save akechi-haruka/7a772efc7f4497492661731cbb1d4ccb to your computer and use it in GitHub Desktop.

Select an option

Save akechi-haruka/7a772efc7f4497492661731cbb1d4ccb to your computer and use it in GitHub Desktop.
Chunithm matching network test
try {
$peerIP = "gmg.hopto.org"
$peerPort = 53488
write-host "Sending UDP $($peerIP):$($peerPort)"
$client = new-object net.sockets.udpclient
$client.Client.SendTimeout = 2000;
$client.Client.ReceiveTimeout = 2000;
$client.Client.SetSocketOption([System.Net.Sockets.SocketOptionLevel]::Socket, [System.Net.Sockets.SocketOptionName]::ReuseAddress, $true)
$LocalIpEndPoint = New-Object System.Net.IPEndPoint([system.net.ipaddress]::any), $peerPort
$client.Client.Bind($LocalIpEndPoint)
$send = [text.encoding]::ascii.getbytes("1")
[void] $client.send($send, $send.length, $peerIP, $peerPort)
$ipep = new-object net.ipendpoint([net.ipaddress]::any, 0)
write-host "Preparing receive at $($ipep)"
$receive = $client.receive([ref]$ipep)
write-host "Data received from $($ipep)"
echo ([text.encoding]::ascii.getstring($receive))
$client.close()
write-host "Success!"
$peerPort = 53490
write-host "Sending UDP $($peerIP):$($peerPort)"
$client = new-object net.sockets.udpclient
$client.Client.SendTimeout = 2000;
$client.Client.ReceiveTimeout = 2000;
$client.Client.SetSocketOption([System.Net.Sockets.SocketOptionLevel]::Socket, [System.Net.Sockets.SocketOptionName]::ReuseAddress, $true)
$LocalIpEndPoint = New-Object System.Net.IPEndPoint([system.net.ipaddress]::any), $peerPort
$client.Client.Bind($LocalIpEndPoint)
$send = [text.encoding]::ascii.getbytes("1")
[void] $client.send($send, $send.length, $peerIP, $peerPort)
$ipep = new-object net.ipendpoint([net.ipaddress]::any, 0)
write-host "Preparing receive at $($ipep)"
$receive = $client.receive([ref]$ipep)
write-host "Data received from $($ipep)"
echo ([text.encoding]::ascii.getstring($receive))
$client.close()
write-host "Success!"
}
catch {
Write-Host $_
}
finally {
pause
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment