summaryrefslogtreecommitdiff
path: root/util/ip.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/ip.go')
-rw-r--r--util/ip.go32
1 files changed, 0 insertions, 32 deletions
diff --git a/util/ip.go b/util/ip.go
deleted file mode 100644
index 239973a..0000000
--- a/util/ip.go
+++ /dev/null
@@ -1,32 +0,0 @@
1package util
2
3import (
4 "net"
5 "regexp"
6)
7
8// Matches:
9// - IPv4: 192.168.1.1
10// - IPv4 + Port: 192.168.1.1:2020
11// - IPv6 + Port: [fe80::551f:5aff:49cf:13e4]:2020
12// - IPv6: fe80::551f:5aff:49cf:13e4
13//
14// Return Order: []string{matched, IPv4, IPv6 (port notation), IPv6 (raw notation), Port
15var ipRegexp = regexp.MustCompile(`(?:((?:\d+\.){3}\d+)|\[([^\]]+)\]|([0-9a-f:]+))(?::(\d+))?`)
16
17func ParseIP(s string) net.IP {
18 ips := ipRegexp.FindStringSubmatch(s)
19 if ips == nil {
20 return nil
21 }
22
23 if ips[1] != "" {
24 return net.ParseIP(ips[1])
25 } else if ips[2] != "" {
26 return net.ParseIP(ips[2])
27 } else if ips[3] != "" {
28 return net.ParseIP(ips[3])
29 } else {
30 return nil
31 }
32}