Skip to content

Instantly share code, notes, and snippets.

@double-p
Created June 2, 2019 10:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save double-p/9e71a63b9969b4669d04ee57591a8433 to your computer and use it in GitHub Desktop.
# ifconfig output like
tap0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr fe:e1:ba:d3:98:45
description: vm1-if0-myvm
index 73 priority 0 llprio 3
groups: tap
status: active
inet 100.64.1.2 netmask 0xfffffffe
tap1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr fe:e1:ba:d4:a7:78
description: vm2-if0-myvm2
index 74 priority 0 llprio 3
groups: tap
status: active
inet 100.64.2.2 netmask 0xfffffffe
tap2: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr fe:e1:ba:d5:ad:bd
description: vm3-if0-3myvm
index 75 priority 0 llprio 3
groups: tap
status: active
inet 100.64.3.2 netmask 0xfffffffe
parse.awk:
BEGIN { tap_name = "" ; tap_ip = ""; tap_found = "" }
$1 ~ /tap/ {
tap_name = $1
}
$2 ~ /vm2-if0-myvm2/ {
tap_found = 1
}
$1 ~ /inet/ {
if (tap_found == 1) {
tap_ip = $2
printf("name: %s ip: %s\n", tap_name, tap_ip)
exit
}
}
==
ssfnhv011$ awk -f parse.awk < tapconfig
name: tap1: ip: 100.64.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment