I was working on this to work on all three platforms, and have come up with the following code. It has been tested and works on Windows 7 Home, OS X (10.9), and ubuntu 12.04 LTS. I include the code for the main call and two of my little utility string functions that are needed. It would probably be better with RegEx, but that’s not my strength.
(As an added note, the Mac version runs more slowly as the terminal call Current Network Information: brings up information about every Wi-Fi router in range.)
[code]Function SSID() As String
//Figure out what SSID we are connected to.
// We are looking by the Hardware specific Console or Terminal call.
// 20131208 gfmc
Dim SSID, sBefore, sAfter, sHold, cmd As String
Dim sh As Shell
#if targetMacOS
sBefore = “Current Network Information:”
sAfter = “:”
cmd = “system_profiler SPAirPortDataType”
#elseif TargetWin32
sBefore = "SSID : "
sAfter = EndOfLine
cmd = “NETSH WLAN SHOW INTERFACE”
#elseif TargetLinux Then
sBefore = “ESSID:”
sAfter = EndOfLine
cmd = “iwconfig wlan0”
#endif
sh= New Shell
sh.mode = 0
sh.execute(cmd)
sHold = sh.result
SSID = Trim(GetMiddleText(sHold,sBefore, sAfter))
// get rid of any quotes
SSID = SSID.ReplaceAll(Chr(34), “”)
Return SSID
End Function
[/code]
[code]Function GetMiddleText(Source As String, TxtOpen As String, TxtClose As String, WhichOne As Integer = 1, IncludeMarkText As Boolean = False) As String
//This will look for information in between TxtOpenand TxtClose
// It will return that text for the WhichOneth Time
// and if it says IncludeMarkText, then we’ll send the text back with it
// 20121011, gfmc
Dim posOpen As Integer = -1
Dim posClose As Integer, num As Integer
Dim ct As Integer = Count(Source, TxtOpen)
if ct < WhichOne Then Return “”
While num <> WhichOne
posOpen = posOpen + 1
posOpen = inStr(posOpen, Source, TxtOpen)
num = num + 1
Wend
posClose = inStr((posOpen + TxtOpen.len), Source, TxtClose)
if posClose = 0 Then Return “”
’ we should be at the right open pisition
posOpen = posOpen + TxtOpen.len
Dim RetStr As String = Source.Mid(posOpen, posClose - posOpen)
if IncludeMarkText Then
RetStr = TxtOpen + RetStr + TxtClose
End If
Return RetStr
End Function
[/code]
[code]Function Count(Source As String, toFind As String) As Integer
Dim ct As Integer = 0
Dim pos As Integer = 0
pos = inStr(pos, Source, toFind)
While pos <> 0
ct = ct + 1
pos = pos + 1
pos = inStr(pos, Source, toFind)
Wend
Return ct
End Function
[/code]
Hope this helps.
Gary