Quote:
Originally Posted by pr0xibus
and i would like it to grap the mac address of the $interface so i thought
ifconfig $interface > add.txt
put it in a var called $mac
|
do you mean the ip address?
here's what my 'ifconfig wlan0' displays:
ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:21:5d:b2:e5:96
inet addr:10.62.11.219 Bcast:10.62.11.223 Mask:255.255.255.224
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1630626 errors:0 dropped:0 overruns:0 frame:0
TX packets:1040182 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2140727532 (1.9 GiB) TX bytes:243190342 (231.9 MiB)
The IP address can be seen in the line with 'inet addr:...'
If I want to store the IP address into a variable, I'd go this
way:
1. make sure the interface is up (ifconfig wlan0 up)
2. make sure the IP address has been attributed
if [ $(ifconfig wlan0 | grep -c 'inet addr:') -eq 0 ]; then
#no ip address found
... exit the script ...
fi
3. the ip address exists, store it in the variable mac:
mac=$(ifconfig wlan0 | grep 'inet addr:' | sed 's?.*inet addr:\([0-9][.0-9]*\).*$?\1?')
4. check:
echo $mac
should display:
10.62.11.219
replace wlan0 by the name of your interface if it's different