AutoIt Forums: Get default gateway - AutoIt Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Get default gateway

#1 User is offline   botanic 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 204
  • Joined: 12-December 06

Posted 16 January 2009 - 10:23 PM

Is there any easy way to get this?
I tried
[ autoIt ]    ( Popup )
$tmp = RunWait("route print 0.0.0.0")

I was just going to format the string however that returns 0 how can I get the text that is normally printed to the command prompt?

#2 User is offline   Andreik 

  • When the words fail... music speaks
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,945
  • Joined: 13-April 08
  • Location:Romania

Posted 16 January 2009 - 10:33 PM

View Postbotanic, on Jan 17 2009, 12:23 AM, said:

Is there any easy way to get this?
I tried
[ autoIt ]    ( Popup )
$tmp = RunWait("route print 0.0.0.0")

I was just going to format the string however that returns 0 how can I get the text that is normally printed to the command prompt?

Try this:
[ code='text' ]    ( Popup )
#include <Process.au3> MsgBox(0,"Default Gateway",GetDefaultGateway()) Func GetDefaultGateway()     _RunDOS("ipconfig >" & @TempDir & "\gateway.dat")     $FILE = FileOpen(@TempDir & "\gateway.dat",0)     $INDEX = 1     While 1         $LINE = FileReadLine($FILE,$INDEX)         If @error = -1 Then Exit         $SPLIT = StringSplit($LINE,":")         If IsArray($SPLIT) Then             If StringInStr($SPLIT[1],"Default Gateway") <> 0 Then Return StringStripWS($SPLIT[2],4)         EndIf         $INDEX += 1     WEnd     FileClose($FILE) EndFunc


#3 User is offline   botanic 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 204
  • Joined: 12-December 06

Posted 16 January 2009 - 10:35 PM

nevermind got it

[ autoIt ]    ( ExpandCollapse - Popup )
Func _get_default_gateway()     $output = _get_cmd_output("netstat -rn")     $arr = StringSplit($output, "0.0.0.0", 1)     $arr2 = StringStripWS($arr[3], 1)     $arr2 = StringSplit($arr2, " ")     Return $arr2[1] EndFunc Func _get_cmd_output($cmd)         $cmd_timeout = 2000         $pid = Run($cmd,@WorkingDir,@SW_HIDE,2)     $timer = TimerInit()     while (ProcessExists($pid))         sleep(50)         If TimerDiff($timer) > $cmd_timeout Then ProcessClose($pid)     WEnd     $output = StdoutRead($pid)         Return StringStripCR($output) EndFunc


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users