From 544ede719c7706078f93d8e74d0503a7d8e44bf1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 20 Mar 2020 23:02:08 +0100 Subject: [PATCH] Add network name reference for endpoint lists --- network/reference/ports.go | 78 ++++++++++++++++++++++++++++++++++ network/reference/protocols.go | 27 ++++++------ 2 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 network/reference/ports.go diff --git a/network/reference/ports.go b/network/reference/ports.go new file mode 100644 index 00000000..b8a70f95 --- /dev/null +++ b/network/reference/ports.go @@ -0,0 +1,78 @@ +package reference + +import ( + "strconv" + "strings" +) + +var ( + portNames = map[uint16]string{ + 20: "FTP-DATA", + 21: "FTP", + 22: "SSH", + 23: "TELNET", + 25: "SMTP", + 43: "WHOIS", + 53: "DNS", + 67: "DHCP-SERVER", + 68: "DHCP-CLIENT", + 69: "TFTP", + 80: "HTTP", + 110: "POP3", + 123: "NTP", + 143: "IMAP", + 161: "SNMP", + 179: "BGP", + 194: "IRC", + 389: "LDAP", + 443: "HTTPS", + 587: "SMTP-ALT", + 465: "SMTP-SSL", + 993: "IMAP-SSL", + 995: "POP3-SSL", + } + + portNumbers = map[string]uint16{ + "FTP-DATA": 20, + "FTP": 21, + "SSH": 22, + "TELNET": 23, + "SMTP": 25, + "WHOIS": 43, + "DNS": 53, + "DHCP-SERVER": 67, + "DHCP-CLIENT": 68, + "TFTP": 69, + "HTTP": 80, + "POP3": 110, + "NTP": 123, + "IMAP": 143, + "SNMP": 161, + "BGP": 179, + "IRC": 194, + "LDAP": 389, + "HTTPS": 443, + "SMTP-ALT": 587, + "SMTP-SSL": 465, + "IMAP-SSL": 993, + "POP3-SSL": 995, + } +) + +// GetPortName returns the name of a port number. +func GetPortName(port uint16) (name string) { + name, ok := portNames[port] + if ok { + return name + } + return strconv.Itoa(int(port)) +} + +// GetPortNumber returns the number of a port name. +func GetPortNumber(port string) (number uint16, ok bool) { + number, ok = portNumbers[strings.ToUpper(port)] + if ok { + return number, true + } + return 0, false +} diff --git a/network/reference/protocols.go b/network/reference/protocols.go index 326ea885..8d193817 100644 --- a/network/reference/protocols.go +++ b/network/reference/protocols.go @@ -1,6 +1,9 @@ package reference -import "strconv" +import ( + "strconv" + "strings" +) var ( protocolNames = map[uint8]string{ @@ -9,20 +12,20 @@ var ( 6: "TCP", 17: "UDP", 27: "RDP", - 58: "ICMPv6", + 58: "ICMP6", 33: "DCCP", - 136: "UDPLite", + 136: "UDP-LITE", } protocolNumbers = map[string]uint8{ - "ICMP": 1, - "IGMP": 2, - "TCP": 6, - "UDP": 17, - "RDP": 27, - "DCCP": 33, - "ICMPv6": 58, - "UDPLite": 136, + "ICMP": 1, + "IGMP": 2, + "TCP": 6, + "UDP": 17, + "RDP": 27, + "DCCP": 33, + "ICMP6": 58, + "UDP-LITE": 136, } ) @@ -37,7 +40,7 @@ func GetProtocolName(protocol uint8) (name string) { // GetProtocolNumber returns the number of a IP protocol name. func GetProtocolNumber(protocol string) (number uint8, ok bool) { - number, ok = protocolNumbers[protocol] + number, ok = protocolNumbers[strings.ToUpper(protocol)] if ok { return number, true }