@@ -29,27 +29,27 @@ def close(signum, frame):
2929
3030
3131def link_up ():
32- ret = run_command (['ip' , 'link' , 'show' , ARGS .INTERFACE ])
32+ ret = run_command (['ip' , 'link' , 'show' , ARGS .INTERFACE ], systemd = ARGS . SYSTEMD )
3333 return not ret .returncode
3434
3535
3636def ping (ip : Union [IPv4Address , IPv6Address ]):
37- ret = run_command (['ping' , '-W5' , '-c3' , '-I' , ARGS .INTERFACE , str (ip )])
37+ ret = run_command (['ping' , '-W5' , '-c3' , '-I' , ARGS .INTERFACE , str (ip )], systemd = ARGS . SYSTEMD )
3838 return not ret .returncode
3939
4040
4141def add_subnet (subnet : Union [IPv4Network , IPv6Network ]):
42- ret = run_command (['ip' , 'route' , 'add' , str (subnet ), 'dev' , ARGS .INTERFACE , 'scope' , 'link' , 'metric' , str (ARGS .METRIC )])
42+ ret = run_command (['ip' , 'route' , 'add' , str (subnet ), 'dev' , ARGS .INTERFACE , 'scope' , 'link' , 'metric' , str (ARGS .METRIC )], systemd = ARGS . SYSTEMD )
4343 return not ret .returncode
4444
4545
4646def remove_subnet (subnet : Union [IPv4Network , IPv6Network ]):
47- ret = run_command (['ip' , 'route' , 'del' , str (subnet ), 'dev' , ARGS .INTERFACE ])
47+ ret = run_command (['ip' , 'route' , 'del' , str (subnet ), 'dev' , ARGS .INTERFACE ], systemd = ARGS . SYSTEMD )
4848 return not ret .returncode
4949
5050
5151def subnet_exists (subnet : Union [IPv4Network , IPv6Network ]):
52- ret = run_command (['ip' , 'route' , 'show' , str (subnet ), 'dev' , ARGS .INTERFACE ])
52+ ret = run_command (['ip' , 'route' , 'show' , str (subnet ), 'dev' , ARGS .INTERFACE ], systemd = ARGS . SYSTEMD )
5353 return not ret .returncode and bool (ret .stdout )
5454
5555
@@ -80,6 +80,7 @@ def main():
8080 print ('This program must be run with root privileges.' )
8181 sys .exit (0 )
8282 parse_args ()
83+ ARGS .SYSTEMD = not run_command (['pidof' , 'systemd' ], systemd = False ).returncode
8384 print (header ('WireGuard Subnets' ))
8485 print (f'Interface: { ARGS .INTERFACE } \n Recheck period: { ARGS .PERIOD } s\n Metric: { ARGS .METRIC } \n Subnets: ' )
8586 collections .deque (print (f' • { subnet } behind { ip } ' ) for ip_subnets in ARGS .IPS_SUBNETS for ip , subnets in ip_subnets .items () for subnet in subnets )
0 commit comments