Created
April 2, 2024 17:43
-
-
Save akechi-haruka/781cec2b2c49e75d70edda30f5559d52 to your computer and use it in GitHub Desktop.
Chrono Regalia Network Test Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try { | |
| $peerIP = "5.7.3.1" | |
| $localIP = Get-NetIPAddress -AddressFamily IPV4 | Where-Object IPAddress -Like "5.7.3.*" | Select-Object IPAddress | |
| if ($localIP -eq $null) { | |
| write-host "VPN not found, using public IP address..." | |
| $peerIP = "gmg.hopto.org" | |
| } | |
| $peerPort = 53960 | |
| write-host "Connecting to TCP $($peerIP):$($peerPort)" | |
| $client = new-object net.sockets.tcpclient | |
| $client.Client.SendTimeout = 2000; | |
| $client.Client.ReceiveTimeout = 2000; | |
| $success = $client.connectasync($peerIP, $peerPort).wait(2000) | |
| $client.close() | |
| if ($success -eq $false){ | |
| write-host "Failed!" | |
| return | |
| } | |
| write-host "Success!" | |
| $peerPort = 53961 | |
| 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