Find gateway of an interface
For a bash integration, i need to retrieve the default gateway from an
interface.
here is the output of the command route -n
Table de routage IP du noyau
Destination Passerelle Genmask Indic Metric Ref Use Iface
0.0.0.0 p.p.p.p 128.0.0.0 UG 0 0 0 tun0
0.0.0.0 x.x.x.x 0.0.0.0 UG 100 0 0 eth0
10.43.0.1 10.43.0.5 255.255.255.255 UGH 0 0 0 tun0
10.43.0.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
31.220.30.224 88.191.142.1 255.255.255.255 UGH 0 0 0 eth0
x.x.x.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
128.0.0.0 10.43.0.5 128.0.0.0 UG 0 0 0 tun0
I try to capture gateway (Passerelle in French) for Iface tun0.
This regex is working on Rubular:
^[0\.]+\s+([\w\.]+)\s+.*UG.*tun0$
But this shell command doesn't work:
route -n |egrep -oh '^[0\.]+\s+([\w\.]+)\s+.*UG.*tun0$'
Please, tell me why ?
No comments:
Post a Comment