best method to determine network devices in a script?
Hi. Let me start by saying I googled for answers to both of these for about a half hour, to no avail. I found related topics; got close! But, alas, no cigar. As part of a small script I'm using the following to get the name of my network interface, "eth0", and tell it to another command.
Code:
iface=$(ifconfig -s | head -n 2 | tail -n 1 | head -c 8) Also, I'm retrieving my gateway's internal IP using: Code:
nameserver=$(cat /etc/resolv.conf | tail -c14) Thanks for your time. |
If you ust want it for your system, just run the first parts
/sbin/ifconfig -s or /sbin/route and cat /etc/resolv.conf and adapt accordingly. If you truly want intelligent parsing, I'd recommend using Perl. |
querying /etc/resolv.conf for the gateway address is not the best approach.. that is the DNS server and is not always the gateway. you would be better off querying with route.
dfgw=$(route | grep default | head -c 30 | tail -c 14) |
Python's tough for me, so Perl's out. :D Route, otoh, suits me. Thanks guys!
|
All times are GMT -5. The time now is 09:20 AM. |