Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

HOW TO DISPLAY SELECTED WIFI AP'S MAC

i use this to detect if a selected wifi is broadcasting:

@echo off
for /F "tokens=3 delims=: " %%a in ('netsh wlan show networks mode^=bssid ^| findstr MyWiFi') do set APname=%%a
for /F "tokens=3 delims=: " %%b in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set mac=%%b
echo APname
echo mac
pause

i want to filter "MyWiFi" 's mac address only, now i'm using this but it fails because something is wrong and missing in this code:
for /F "tokens=3 delims=: " %%b in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set mac=%%b


i want to display this output:
MyWifi AP name
90511CD97HDE will remove ":" in 90:51:1c:D9:7H:DE


hope you can help me guyz thank you very much :D
Please use code tags OP as your thread looks messy.
Your code:

Code
@echo off
for /F "tokens=3 delims=: " %%a in ('netsh wlan show networks mode^=bssid ^| findstr MyWiFi') do set APname=%%a
for /F "tokens=3 delims=: " %%b in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set mac=%%b
echo APname
echo mac
pause

Modify it to this:

Code
@echo off
for /F "tokens=3 delims=: " %%a in ('netsh wlan show networks mode^=bssid ^| findstr MyWiFi') do set APname=%%a
for /F "tokens=3 delims=: " %%b in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set mac=%%b
echo %APname%
echo %mac::=%
pause

The bit that removes the colons is this:
Code
%mac::=%

This is string substitution.
For example:
Code
set var=Cats
echo %var%
echo %var:C=M%

Code
Cats
Mats

In the above example, we substitue all instances of "C" in %var% with "M".
In the original example, we're substiting ":" with "", in other words, we're removing any colons.
hi Annik.exe your my idol man thank you very much for your response..
i'm here in the Philippines i'm trying to automate the default password of any Zyxel PLDT Brand Router.

the default password of WIFI AP here is always "PLDTWIFI+"last 5 characters of MAC address"
example if the MAC address of that router is A1:B2:C3:D4:E5:F6 then you can connect to it
with prefix "PLDTWIFI" + suffix "4E5F6" the default password will be "PLDTWIFI4E5F6"

@echo off
for /F "tokens=3 delims=: " %%a in ('netsh wlan show networks mode^=bssid ^| findstr PLDTMyDSL') do set AP=%%a
echo %AP%
for /F "delims=: tokens=5" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set b1=%%a
for /F "delims=: tokens=6" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set b2=%%a
for /F "delims=: tokens=7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set b3=%%a
echo The Password is: PLDTWIFI%b1%%b2%%b3%

this is my code so far and its not complete but i think there's shorter code than this..

this is the last 6 digit of Router's mac address:
%b1%%b2%%b3%

i'm so noob. can i ask how can i remove the 1st letter from left of "D4E5F6" to become "4E5F6" ? 😑
Ask your questions with confidence. We're all here to learn too. :>

Code
for /F "delims=: tokens=5" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set b1=%%a
for /F "delims=: tokens=6" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set b2=%%a
for /F "delims=: tokens=7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do set b3=%%a

This code could be shortened to just this:
Code
for /F "delims=: tokens=5,6,7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do (set "b=%%a%%b%%c")

Then %b% = D4E5F6

We want to get rid of the first character (the "D"). We can do this with string manipulation:
Code
set "b=%b:~1,5%"

We're modifying %b% to become %b:~1,5%
The first number (1) refers to the index number of each character.
D = index 0
4 = index 1
E = index 2
5 = index 3
F = index 4
6 = index 5

The second number expresses how many characters to capture. In our case we put "5" so this means "starting from index 1, capture 5 characters".

That gives us this:
Code
4E5F6

..which is what you want. :>

Here are some more examples of string manipulation using this method:

Code
set "cat=Cats are best"
echo %cat%
Code
Cats are best

Code
set "cat=Cats are best"
echo %cat:~1,5%
Code
ats a

Code
set "cat=Cats are best"
echo %cat:~2,9%
Code
ts are be

Code
set "cat=Cats are best"
echo %cat:~0,3%
Code
Cat

Code
set "cat=Cats are best"
echo %cat:~9,4%
Code
best

Code
set "cat=Cats are best"
echo %cat:~6,7%
Code
re best

You can also use negative numbers to select from the end of the string:
Code
set "cat=Cats are best"
echo %cat:~-4,4%
Code
best

...or to remove from the end of the string:
Code
set "cat=Cats are best"
echo %cat:~0,-2%
Code
Cats are be

Hope this helps. :>
thank you man for your guides, you helped me alot.. :D
No problem friend, glad I could assist you. :> Please don't hesitate to ask further questions if there's anything else you're stuck on. :>
Thanks annik...
the script im trying to make still have bugs when scanning the mac address of Zyxel AP is not filtered, sometimes it can get other mac address not the target AP:
for /F "delims=: tokens=5,6,7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do (set "b=%%a%%b%%c") i'll try to fix later... for now i have this code and its partially working.. credits to your help XD

@echo off
for /F "tokens=3 delims=: " %%a in ('netsh wlan show networks mode^=bssid ^| findstr PLDTMyDSL') do set AP=%%a
echo Trying to connect to %AP%
for /F "delims=: tokens=5,6,7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do (set "b=%%a%%b%%c")
echo %b%
set "b=%b:~1,5%"
echo The Password is: PLDTWIFI%b%
set passkey=PLDTWIFI%b%
echo ^<?xml version="1.0"?^> > PLDTMyDSL.xml
echo ^<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"^> >> PLDTMyDSL.xml
echo ^<name^>%AP%^</name^> >> PLDTMyDSL.xml
echo ^<SSIDConfig^> >> PLDTMyDSL.xml
echo ^<SSID^> >> PLDTMyDSL.xml
echo ^<name^>%AP%^</name^> >> PLDTMyDSL.xml
echo ^</SSID^> >> PLDTMyDSL.xml
echo ^</SSIDConfig^> >> PLDTMyDSL.xml
echo ^<connectionType^>ESS^</connectionType^> >> PLDTMyDSL.xml
echo ^<connectionMode^>auto^</connectionMode^> >> PLDTMyDSL.xml
echo ^<MSM^> >> PLDTMyDSL.xml
echo ^<security^> >> PLDTMyDSL.xml
echo ^<authEncryption^> >> PLDTMyDSL.xml
echo ^<authentication^>WPA2PSK^</authentication^> >> PLDTMyDSL.xml
echo ^<encryption^>AES^</encryption^> >> PLDTMyDSL.xml
echo ^<useOneX^>false^</useOneX^> >> PLDTMyDSL.xml
echo ^</authEncryption^> >> PLDTMyDSL.xml
echo ^<sharedKey^> >> PLDTMyDSL.xml
echo ^<keyType^>passPhrase^</keyType^> >> PLDTMyDSL.xml
echo ^<protected^>false^</protected^> >> PLDTMyDSL.xml
echo ^<keyMaterial^>%passkey%^</keyMaterial^> >> PLDTMyDSL.xml
echo ^</sharedKey^> >> PLDTMyDSL.xml
echo ^</security^> >> PLDTMyDSL.xml
echo ^</MSM^> >> PLDTMyDSL.xml
echo ^</WLANProfile^> >> PLDTMyDSL.xml
::automaticaly connect if wifi ap is broadcasting
netsh wlan add profile filename="PLDTMyDSL.xml"

setlocal enabledelayedexpansion enableextensions

netsh wlan show interfaces|find /i /c "Infrastructure" >NUL && (

color a
echo * Success.. Connected to the Wifi Network XD

pause

)

goto eoc:
echo * Conneting Failed
pause
Well, if there's only one particular wireless network that you're trying to sign into, purrhaps try adding an extra FINDSTR to only look at lines that contain the desired MAC Address.

For example, you could change this:
Code
for /F "delims=: tokens=5,6,7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do (set "b=%%a%%b%%c")

...to this:

Code
for /F "delims=: tokens=5,6,7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID ^| Findstr D4:E5:F6') do (set "b=%%a%%b%%c")

That way, it won't pick up a different wireless network some of the time.
It would be best to put the full MAC Address in there. I only know the last 3 octets from what you've told me.

Does that help? :>
is there a way to scan the target AP's mac address? i'm not just trying to connect to one particular network i also want to add new scanned AP's profile. i'm trying to make a simple automated Laptop Anti-theft tool for my friend which scans Zyxel WiFi and connect to internet and send GPS data to email... i'll prefer on Zyxel because there are many available AP anywhere in our area..i prefer to connect to it because OPEN Networks are usually slow.. :)
(Dec 8, 2014 07:37 AM)/{evin Mitnic/{ Wrote:  is there a way to scan the target AP's mac address? i'm not just trying to connect to one particular network i also want to add new scanned AP's profile. i'm trying to make a simple automated Laptop Anti-theft tool for my friend which scans Zyxel WiFi and connect to internet and send GPS data to email... i'll prefer on Zyxel because there are many available AP anywhere in our area..i prefer to connect to it because OPEN Networks are usually slow.. :)

Yeah there is. :> But you would need to be connected to the wireless network first.

You must first know the IP address of the AP.
Lets suppose it's 192.168.1.254

1. Ping the AP:
Code
ping -n 1 192.168.1.254

2. Now look at the following command:
Code
arp -a

3. We can be more specific:
Code
arp -a | Findstr 192.168.1.254

That returns the line of text with the AP's MAC Address listed on the right hand side.
Then you can use the string manipulation techniques I showed you earlier to capture the MAC.
(Dec 8, 2014 08:05 AM)annikk.exe Wrote:  Yeah there is. :> But you would need to be connected to the wireless network first.

You must first know the IP address of the AP.
Lets suppose it's 192.168.1.254

1. Ping the AP:
Code
ping -n 1 192.168.1.254

2. Now look at the following command:
Code
arp -a

3. We can be more specific:
Code
arp -a | Findstr 192.168.1.254

That returns the line of text with the AP's MAC Address listed on the right hand side.
Then you can use the string manipulation techniques I showed you earlier to capture the MAC.

yup .. i've already seen that in your NetDisplay script but its hard to capture the Mac if not connected to AP.. because this code:
for /F "delims=: tokens=5,6,7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do (set "b=%%a%%b%%c")

displays only the last SSID (index) of scanned AP's it conflicts the code above maybe i should use third party software? but it seems nothing available..
(Dec 9, 2014 11:09 PM)/{evin Mitnic/{ Wrote:  yup .. i've already seen that in your NetDisplay script but its hard to capture the Mac if not connected to AP.. because this code:
for /F "delims=: tokens=5,6,7" %%a in ('netsh wlan show networks mode^=bssid ^| findstr BSSID') do (set "b=%%a%%b%%c")

displays only the last SSID (index) of scanned AP's it conflicts the code above maybe i should use third party software? but it seems nothing available..

God damn, use the code tags!

Code
@echo off
setlocal enabledelayedexpansion
set ss=1
set count=0
for /f "delims=: tokens=1*" %%0 in ('netsh wlan show networks mode^=bssid ^| findstr "SSID"') do (
    set work=%%1
    set work=!work:~1!
    if "!work!"=="" set work=UNKN
    if !ss!==1 (
        set /a count+=1
        set ss=0
        set ssid!count!=!work!
    ) else (
        set bssid!count!=!work!
        set ss=1
    )
)

for /l %%a in (1,1,%count%) do echo %%a: !ssid%%a! !bssid%%a!
pause

Will display every available network and the MAC address.
(Dec 10, 2014 12:49 AM)White Light Wrote:  God damn, use the code tags!

Code
@echo off
setlocal enabledelayedexpansion
set ss=1
set count=0
for /f "delims=: tokens=1*" %%0 in ('netsh wlan show networks mode^=bssid ^| findstr "SSID"') do (
    set work=%%1
    set work=!work:~1!
    if "!work!"=="" set work=UNKN
    if !ss!==1 (
        set /a count+=1
        set ss=0
        set ssid!count!=!work!
    ) else (
        set bssid!count!=!work!
        set ss=1
    )
)

for /l %%a in (1,1,%count%) do echo %%a: !ssid%%a! !bssid%%a!
pause

Will display every available network and the MAC address.

Code
@echo off
echo Yez Sir Thank you very much for helping me solve this problem
echo You're a real batch genius!
pause


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by friiz1337Feb 6, 2020 02:37 PM 8 373 Feb 6, 2020 02:37 PM
Last Post: friiz1337
[Python] by xthanosDec 7, 2016 04:25 AM 8 271 Dec 7, 2016 04:25 AM
Last Post: xthanos
[.NET] by Tɦɛ AlexDec 22, 2015 12:46 PM 2 336 Dec 22, 2015 12:46 PM
Last Post: Tɦɛ Alex