question about router ip

Mac OSX specific forum
Armoured
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

question about router ip

Post by Armoured »

Hi, :)
How I can retrieve with PureBasic the ip of my router?


Thanks
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: question about router ip

Post by deseven »

Code: Select all

Procedure.s AppleScript(Script.s)
  Protected retVal.s, strVal, numItems, i
  Protected aScript = CocoaMessage(0, CocoaMessage(0, CocoaMessage(0, 0, "NSAppleScript alloc"), "initWithSource:$", @Script), "autorelease")
  Protected eventDesc = CocoaMessage(0, aScript, "executeAndReturnError:", #nil)
  If eventDesc
    numItems = CocoaMessage(0, eventDesc, "numberOfItems")
    If numItems
      For i = 1 To numItems
        strVal = CocoaMessage(0, CocoaMessage(0, eventDesc, "descriptorAtIndex:", i), "stringValue")
        If strVal
          retVal + PeekS(CocoaMessage(0, strVal, "UTF8String"), -1, #PB_UTF8)
          If i <> numItems : retVal + #LF$ : EndIf
        EndIf
      Next
    Else
      strVal = CocoaMessage(0, eventDesc, "stringValue")
      If strVal : retVal = PeekS(CocoaMessage(0, strVal, "UTF8String"), -1, #PB_UTF8) : EndIf
    EndIf
  EndIf
  ProcedureReturn retVal 
EndProcedure

routerIP.s="set the routerIP to do shell script " + #DQUOTE$ + "route get default | grep gateway | tr -d ' ' | cut -f2 -d':'" + #DQUOTE$
Debug AppleScript(routerIP)
Or you can manually run `route get default | grep gateway | tr -d ' ' | cut -f2 -d':'` and read stdout.
Post Reply