When i debug it i can see that all is correct until this line is executed:
$ReceiveBytes = $Udpclient.Receive([ref]$IPEndPoint)
It times out after 20 sec with the following exception:
Exception calling “Receive” with “1” argument(s): “A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond”
When i test the availability of the same port with Microsoft’s port query utility i get success in 5 sec:
portqry.exe -n servername -e portnumber -p UDP
i also tried the Test-Port PS script and it failed.
i am puzzled.
Can you help?
The test-port here function worked for me (Browse code samples | Microsoft Docs), at least with one of Comcast’s dns servers. I guess it depends on if the udp server responds to garbage. It’s not like you can test making a syn connection with tcp. The code at the bottom of Querying UDP Ports with PowerShell: Part 2 | Learn Powershell | Achieve More didn’t work for me. Strange, sending “TEST” to the Comcast dns server gets no response, but “Anybody there?” does. test-port sends the date.
PS /Users/js/Downloads> Test-Port -comp cdns01.comcast.net -port 53 -udp -verbose
VERBOSE: Making UDP connection to remote server
VERBOSE: Sending message to remote host
VERBOSE: Creating remote endpoint
VERBOSE: Waiting for message return
VERBOSE: Connection Successful
Server : cdns01.comcast.net
Port : 53
TypePort : UDP
Open : True
Notes : 07??
Also osx has nc (netcat):
PS /Users/js> nc -zuv cdns01.comcast.net 53
found 0 associations
found 1 connections:
1: flags=82
outif (null)
src 192.168.1.108 port 50158
dst 75.75.75.75 port 53
rank info not available
Connection to cdns01.comcast.net port 53 [udp/domain] succeeded!
Actually your code works for me. The 14 is from updclient.send() and asciiencoder.getstring() returns the weird characters.
Good day.
I’ve tinkered a bit more.
$Udpclient.Connect opens a local listening udp port and sets accordingly the $Udpclient.client.localendpoint
So after $Udpclient.Connect one can see among udp ports the one that $Udpclient.client.localendpoint describes.
I went to the remote server and tried to portqry.exe that port on my local machine and failed.
With that i declared the problem a cold case.
As to asciiencoder.getstring() returning weird characters it seems to me that you hit upon a service that takes whatever string you send to it and leaves only first two and the last character.