mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Suggest using -listallnetworkservices
Signed-off-by: Dariush Ahmadi <68775308+gdariushahmadi@users.noreply.github.com>
This commit is contained in:
parent
6ebd3f9a8e
commit
1b6da347eb
@ -112,20 +112,32 @@ func (p *DarwinSystemProxy) update0() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMacOSActiveNetworkHardwarePorts() ([]string, error) {
|
func getMacOSActiveNetworkHardwarePorts() ([]string, error) {
|
||||||
command := `
|
content, err := shell.Exec("networksetup", "-listallnetworkservices").ReadOutput()
|
||||||
for interface in $(networksetup -listallhardwareports | awk '/Device/ {print $2}'); do
|
|
||||||
if ifconfig $interface | grep -q "inet "; then
|
|
||||||
networksetup -listallhardwareports | awk -v iface=$interface '
|
|
||||||
/Hardware Port/ {port=$3; for(i=4;i<=NF;i++) port=port" "$i}
|
|
||||||
/Device/ {if ($2 == iface) {print port}}'
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
`
|
|
||||||
content, err := shell.Exec("sh", "-c", command).ReadOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
hardwarePorts := strings.Split(strings.TrimSpace(string(content)), "\n")
|
|
||||||
|
lines := strings.Split(strings.TrimSpace(string(content)), "\n")
|
||||||
|
var hardwarePorts []string
|
||||||
|
|
||||||
|
for _, line := range lines {
|
||||||
|
if line == "An asterisk (*) denotes that a network service is disabled." {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if line == "" || strings.HasPrefix(line, "*") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceContent, err := shell.Exec("networksetup", "-getinfo", line).ReadOutput()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(string(serviceContent), "IP address:") {
|
||||||
|
hardwarePorts = append(hardwarePorts, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(hardwarePorts) == 0 {
|
if len(hardwarePorts) == 0 {
|
||||||
return nil, E.New("Active Network Devices not found.")
|
return nil, E.New("Active Network Devices not found.")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user