readmedottxt 1 Posted April 27, 2010 (edited) I found a few default gateway scripts but many error'ed in Win7 and WinPE. This script returns the first default gateway found when you do an ipconfig /all based on a network in the 10.* range. You can change it to 192.* etc quite easily. Hope it's of some use $i = 0 while 1 $i = $i + 1 if $i > 10 Then MsgBox(0, "", "Could not get default gateway, aborting ...", 5) ExitLoop EndIf $foo = Run(@ComSpec & ' /c IpConfig.exe /All | Find "Gateway"', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $line = "" Sleep(1000) $line = StdoutRead($foo) if StringInStr($line, ": 10.") > 0 Then MsgBox(0, "", "Found GW: " & StringMid($line, StringInStr($line, ": 10.") + 2)) ExitLoop EndIf WEnd Edited April 27, 2010 by readmedottxt Share this post Link to post Share on other sites
BrettF 28 Posted April 27, 2010 (edited) Something slightly different: ; Demonstrates StdoutRead() #include <Constants.au3> MsgBox (0, "", _GetDefaultGateway()) Func _GetDefaultGateway() Local $foo = Run(@ComSpec & " /c ipconfig /all | Find ""Gateway""", @SystemDir, @SW_HIDE, $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($foo) If @error Then ExitLoop $array = StringRegExp($line, "(?i)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", 3) If Not @error Then Return SetError(0, 0, $array[0]) WEnd Return SetError(1, 0, False) EndFunc ;==>_GetDefaultGateway Edited April 27, 2010 by BrettF Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Share this post Link to post Share on other sites
ripdad 100 Posted April 27, 2010 $array = StringRegExp("132.234.212.1", "(?i)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", 3) Should be: $array = StringRegExp($line, "(?i)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", 3) "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Share this post Link to post Share on other sites
BrettF 28 Posted April 27, 2010 (edited) woops... Was testing my string regexp.... fixed. Thanks EDIT: Which reminds me. This could also be done with WMI. Edited April 27, 2010 by BrettF Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Share this post Link to post Share on other sites
ripdad 100 Posted April 27, 2010 BrettF: Which reminds me. This could also be done with WMI.Without IpConfig? Where is it?! <grin> "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Share this post Link to post Share on other sites
BrettF 28 Posted April 27, 2010 #include <Array.au3> $a = _GetDefaultGateway() _ArrayDisplay ($a) Func _GetDefaultGateway() Local $count = 0, $aRet[$count+1] $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $colNicConfigs = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 48) For $objNicConfig In $colNicConfigs For $strIPDefaultIPGateway In $objNicConfig.DefaultIPGateway $count += 1 ReDim $aRet[$count+1] $aRet[$count] = $strIPDefaultIPGateway Next Next $aRet[0] = $count Return $aRet EndFunc ;==>_GetDefaultGateway Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Share this post Link to post Share on other sites
ripdad 100 Posted April 27, 2010 Very nice - thanks "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Share this post Link to post Share on other sites
Wilenty 1 Posted May 15, 2010 (edited) Hello And script for RAS ip v4 & gateway {PPP/PPPoE/PPPoA/DialUP} works fine from XP to 7 $RasAPI32 = DllOpen("rasapi32.dll") $RASCONN = DllStructCreate("dword dwSize;hwnd hRasConn;char szEntryName[256];" & _ "char szDeviceType[17]; char szDeviceName[128];" & _ "char szPhonebook[260];" & _ "dword dwSubEntry;byte guidEntry[16];dword dwFlags;byte luid[8]") $Conn = DllStructGetSize($RASCONN) DllStructSetData($RASCONN, "dwSize", $Conn) $Byte = DllStructCreate("dword") DllStructSetData($Byte, 1, $Conn) $Conn = DllStructCreate("dword") $dwRet = DllCall($RasAPI32, "int", "RasEnumConnections", _ "ptr", DllStructGetPtr($RASCONN), _ "ptr", DllStructGetPtr($Byte), _ "ptr", DllStructGetPtr($Conn)) If $dwRet[0] Then Exit MsgBox(16,'dll error', $dwRet[0]) If DllStructGetData($Conn,1) < 1 Then Exit MsgBox(16,'error','no RAS connection!') $RASPPPIP = DllStructCreate("DWORD dwSize; DWORD dwError; CHAR szIpAddress[16]; CHAR szServerIpAddress[16];" & _ "DWORD dwOptions; DWORD dwServerOptions") DllStructSetData($RASPPPIP, "dwSize", DllStructGetSize($RASPPPIP)) $buff = DllStructCreate("dword") DllStructSetData($buff, 1, DllStructGetSize($RASPPPIP)) $dwRet = DllCall($RasAPI32, 'int', "RasGetProjectionInfo", "dword", DllStructGetData($RASCONN, "hRasConn"), "int", 0x8021, "ptr", DllStructGetPtr($RASPPPIP), "ptr", DllStructGetPtr($buff) ) If Not $dwRet[0] Then MsgBox( 64,'RAS Info','Conn: ' & DllStructGetData($RASCONN, "szEntryName") & @CRLF & 'IP: ' & DllStructGetData($RASPPPIP, "szIpAddress") & @CRLF & 'Gateway: ' & DllStructGetData($RASPPPIP, "szServerIpAddress") ) EndIf DllClose($RasAPI32) Greets wilenty. Edited May 15, 2010 by Wilenty Share this post Link to post Share on other sites