I am working on a script that detects CDP information from the network card. The script currently works on my computer, but i would like to make it available for other people. The script currently runs because in the code it has the name of my network card. I would like to make it ask for the network card name (perhaps list the ones available) before running the script. My code is:
#!/usr/bin/awk -f
function red(s) {
printf "\033[1;31m" s "\033[0m "
}
function green(s) {
printf "\033[1;32m" s "\033[0m "
}
function blue(s) {
printf "\033[1;34m" s "\033[0m "
}
BEGIN{
cmd = "tcpdump -nvi enp0s25 -s 1500 ether dst 01:00:0c:cc:cc:cc -c 1"
while ((cmd | getline) > 0) {
str="Device-ID:Cisco IOS Software:Port-ID:VTP:Address:VLAN:Duplex:VoIP:"
split(str,s,":")
for(i=1;i<=length(s);i++){
if ($0 ~ s[i] && s[i]){
if (i==1){
print "\n";
print red("Device Name: ") green($7);
}
else if (i==2){
print red("Software Version: ") green($0) ;
}
else if (i==3){ /*Port*/
print red($1 ": ") green($7);
}
else if (i==4){
print red($1 " " $2 " " $3 ": ") green($9);
}
else if (i==5){
print red("IP Address: ") green($9);
}
else if (i==6){
print red("VLAN: ") green($9);
}
else if (i==7){
print red("DUPLEX: ") green($7);
}
else if (i==8){
print red("Voice VLAN: ") green($13);
}
else{
s[i]=0;print " "}
}
}
}
}
As you can see, it runs the command with my NIC which is enp0s25. I need to make this a variable, that is entered by the user (maybe only once). the best approach would be to enumerate the cards and have the user pick the card he wants using a number. I have NO IDEA how to do this.
tcpdump args | awk 'script') and hard-coding agetlineloop instead?%sequences, you'll get an error. You need to keep the parameter out of the format string. I would dofunction colorize(s, n) { printf "\033[1;%dm%s\033[0m ", n, s }thenfunction red(s) {colorize(s, 31)}, etc