Jump to content

Ip Gateway address


Alv.
 Share

Recommended Posts

How I can get IP Gateway? Usualy I run commanline like this:

ipconfig | find /i "192.168.100.254"

and read %errorlevel% value.

How I can run this comman by AutoIT?

#Include <process.au3>

$value=_RunDOS( "ipconfig | find /i "192.168.100.254"")

doesn't work.

Link to comment
Share on other sites

i would run ipconfig with the std_out flag

then use stringinstring for the ip

then check @error

Hey.

Is it right, you don´t know your gateway that route your internet? Then you can use the tracert command with a url it will give out the used router. Pipe the issue in a file and read that part you need with the appropriate Autoif functions.

a lot take place

[font="Comic Sans Ms"][center]Powered by AutoIt3http://www.wik-eric.de/zips/Synchro2.2.2-4free.zip[/center][/font]

Link to comment
Share on other sites

How I can get IP Gateway? Usualy I run commanline like this:

ipconfig | find /i "192.168.100.254"

and read %errorlevel% value.

How I can run this comman by AutoIT?

#Include <process.au3>

$value=_RunDOS( "ipconfig | find /i "192.168.100.254"")

doesn't work.

Somebody else may post a cool AutoIt function for this, but you can also use a batch file to run:

@echo off
REM GetGw.cmd batch file
ipconfig | find "Gateway" > IpGw.txt
for /f "tokens=2 delims=:" %%i in (IpGw.txt) do set IpGw=%%i
echo %IpGw% > IpGw.txt

Then just read the contents of IpGw.txt, but it will only show the gateway of the LAST instance if there are multiple NICs.

You can also read it from the registry, though it's a small pain to get the NIC instance(s), and the value is different for DHCP or static. This is my idea:

CODE

; Get IP Gateway for all interfaces

#include <array.au3>

$IntfcKey = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"

Dim $Interfaces[1] ; Array of TCPIP interfaces

$Interfaces[0] = 0

For $i = 1 To 10

If RegEnumKey($IntfcKey, $i) = "" Then

ExitLoop

Else

_ArrayAdd($Interfaces, RegEnumKey($IntfcKey, $i))

EndIf

Next

$Interfaces[0] = UBound($Interfaces) - 1 ; Cell [0] = count of TCPIP interfaces

If $Interfaces[0] = 0 Then

MsgBox(16, "Gateway Error", "No TCPIP interfaces found!")

Exit

EndIf

Dim $Gateways[$Interfaces[0] + 1][3] ; 2-D array of interface instances and gateways

$Gateways[0][0] = $Interfaces[0] ; Cell [0][0] = count of instances

For $i = 1 To $Interfaces[0]

$Gateways[$i][0] = $Interfaces[$i]

If RegRead($IntfcKey & "\" & $Interfaces[$i], "EnableDHCP") = 1 Then

$Gateways[$i][1] = 1

$Gateways[$i][2] = RegRead($IntfcKey & "\" & $Interfaces[$i], "DhcpDefaultGateway")

Else

$Gateways[$i][1] = 0

$Gateways[$i][2] = RegRead($IntfcKey & "\" & $Interfaces[$i], "DefaultGateway")

EndIf

If $Gateways[$i][2] = "" Then $Gateways[$i][2] = "(Not Set)"

Next

$Msg = " Interface DHCP? Gateway" & @CRLF & _

"-------------------------------------------------------- ------ -------------" & @CRLF

For $i = 1 To $Gateways[0][0]

$Msg = $Msg & $Gateways[$i][0] & " " & $Gateways[$i][1] & " " & $Gateways[$i][2] & @CRLF

Next

MsgBox(32, "Gateway Information", $Msg)

This will give you gateways for multiple NICs, and wether or not they are DHCP enabled.

:lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

How I can run this comman by AutoIT?

#Include <process.au3>

$value=_RunDOS( "ipconfig | find /i "192.168.100.254"")

doesn't work.

Thanks for all.

I find easy solution:

#Include <process.au3>

$value=_RunDOS( "ipconfig" & '| find /i "192.168.100.254"')

MsgBox(0, "Program returned with exit code:", $value)

I'm confused... (not your fault, it's my normal condition) ;)

After thinking you wanted to know what the gateway was set to, I just noticed that your code through this whole thread has looked for a specific IP address "192.168.100.254", not the current gateway address. If you already know what the gateway is, why look for it unles you just want to know if it is set as expected? The code I posted earlier in this thread will reliably get gateway address(es) from the registry, so this DOS 'find' and '%ERRORLEVEL%' stuff is not necesary.

Am I missing what you are really trying to do? :lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I'm confused... (not your fault, it's my normal condition) ;)

After thinking you wanted to know what the gateway was set to, I just noticed that your code through this whole thread has looked for a specific IP address "192.168.100.254", not the current gateway address. If you already know what the gateway is, why look for it unles you just want to know if it is set as expected? The code I posted earlier in this thread will reliably get gateway address(es) from the registry, so this DOS 'find' and '%ERRORLEVEL%' stuff is not necesary.

Am I missing what you are really trying to do? :lmao:

I have 20 laptops and running 2 scripts

first script in my office network and

second script if laptop connected to another network

Thank for all answers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...