如何检查UDP IP和端口是否打开

How to check the UDP port and IP is opened?

I have checked the net.DialUDP() method but is showing the error ,

"cannot assign requested address"

ln, err := net.DialUDP()

I want to result is "address already in use"

To check if a udp ip and port are opened, try to listen on this port, ie to set up a server on this port. You will likely have an error that the address is already in use.

sAddr, err := net.ResolveUDPAddr("udp", "ipaddress:port")       
if err != nil {
    log.Fatalln(err)
}
sConn, err := net.ListenUDP("udp", sAddr)
if err != nil {
     log.Fatalln(err)
}