You are not logged in.

#1 2010-01-21 18:53:15

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 1,000
Website

Help with bash

Hello,

I need to get AP MAC out of this iwconfig output:

lo        no wireless extensions.

eth0      no wireless extensions.

wifi0     no wireless extensions.

ath0      IEEE 802.11g  ESSID:"linksys"  Nickname:""
          Mode:Managed  Frequency:2.462 GHz  Access Point: 00:11:22:33:44:55
          Bit Rate:48 Mb/s   Tx-Power:18 dBm   Sensitivity=1/1  
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=31/70  Signal level=-63 dBm  Noise level=-94 dBm
          Rx invalid nwid:3152  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

I've done it like this but this regexp I've come up with seems silly:

iwconfig ath0 2>&1 | grep -E -o '[0123456789ABCDEF]{2}:[0123456789ABCDEF]{2}:[0123456789ABCDEF]{2}:[0123456789ABCDEF]{2}:[0123456789ABCDEF]{2}:[0123456789ABCDEF]{2}'

Can you please suggest a more clean way to do it?

P.S. Notice that iwconfig outputs to stderr by default.

.

Last edited by karabaja4 (2010-01-21 18:56:17)

Offline

#2 2010-01-21 19:09:38

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Help with bash

cat /sys/class/net/ath0/address

Offline

#3 2010-01-21 19:30:38

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 1,000
Website

Re: Help with bash

Procyon wrote:

cat /sys/class/net/ath0/address

Please read more carefully, I need access point MAC address (BSSID), not my card MAC smile

Offline

#4 2010-01-21 19:54:16

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: Help with bash

iwconfig 2>&1|sed -n "s/.*Access Point: \(\([0-9A-F]\{2\}:\)\{5\}[0-9A-F]\).*/\1/;T;p"

This works, and only extracts six colon separated double uppercase hexadecimal digits occuring after the string "Access Point: ", however, it can surely be made shorter since the output from iwconfig is not "free" but follows a pattern.
edit:
Case in point:

iwconfig 2>&1| grep "Access Point"|cut -d\  -f18

Last edited by tlvb (2010-01-21 19:56:46)


I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.

Offline

#5 2010-01-21 20:00:35

res
Member
Registered: 2010-01-14
Posts: 55

Re: Help with bash

iwconfig wlan0 | grep -o 'Ac.*' | sed 's,.*: ,,'

Offline

#6 2010-01-21 22:38:01

Bralkein
Member
Registered: 2004-10-26
Posts: 354

Re: Help with bash

iwconfig ath0 | awk '/Ac/ {print $6}'

So many ways smile

Last edited by Bralkein (2010-01-21 22:39:05)

Offline

#7 2010-01-21 23:28:18

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 1,000
Website

Re: Help with bash

Okay, thanks all big_smile

Now, maybe there is some way to get the value direcly?

Something like already mentioned command

cat /sys/class/net/ath0/address

but for AP MAC adress?

Offline

#8 2010-01-21 23:33:23

kwirkie
Member
Registered: 2010-01-09
Posts: 15

Re: Help with bash

 iwconfig ath0 |egrep -o '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'

Offline

Board footer

Powered by FluxBB