Golang net.LookupPort() function example
package net
Golang net.LookupPort() function usage example
package main
import (
"fmt"
"net"
)
func main() {
//-------------------------
network := "tcp"
service := "domain"
portNum, err := net.LookupPort(network, service)
if err != nil {
panic(err)
}
fmt.Printf("Port number for %s network and %s service is : %d \n", network, service, portNum)
//-------------------------
network = "udp"
service = "syslog"
portNum, err = net.LookupPort(network, service)
if err != nil {
panic(err)
}
fmt.Printf("Port number for %s network and %s service is : %d \n", network, service, portNum)
}
// NOTES :
//var porttests = []portTest{
// {"tcp", "echo", 7, true},
// {"tcp", "discard", 9, true},
// {"tcp", "systat", 11, true},
// {"tcp", "daytime", 13, true},
// {"tcp", "chargen", 19, true},
// {"tcp", "ftp-data", 20, true},
// {"tcp", "ftp", 21, true},
// {"tcp", "telnet", 23, true},
// {"tcp", "smtp", 25, true},
// {"tcp", "time", 37, true},
// {"tcp", "domain", 53, true},
// {"tcp", "finger", 79, true},
// {"udp", "echo", 7, true},
// {"udp", "tftp", 69, true},
// {"udp", "bootpc", 68, true},
// {"udp", "bootps", 67, true},
// {"udp", "domain", 53, true},
// {"udp", "ntp", 123, true},
// {"udp", "snmp", 161, true},
// {"udp", "syslog", 514, true},
// {"--badnet--", "zzz", 0, false},
// {"tcp", "--badport--", 0, false},
//}
See also :
https://www.socketloop.com/tutorials/golang-find-network-of-an-ip-address
References :
Advertisement
Something interesting
Tutorials
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+14.4k Golang : How to filter a map's elements for faster lookup
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+18.7k Golang : Implement getters and setters
+9.4k Facebook : Getting the friends list with PHP return JSON format
+15.2k Golang : Get HTTP protocol version example
+15.8k Golang : How to login and logout with JWT example
+9k Golang : Inject/embed Javascript before sending out to browser example
+5.5k Golang : Display advertisement images or strings on random order
+6.5k Golang : Map within a map example
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?