Jump to content

How run ipconfig to find ip address and then ping it


 Share

Recommended Posts

I can run ipconfig by itself and it shows the IP Address. I want know how to ping the resulting IPAddress after finding it.

I tried this script:

-----

; END

Func ping2Pressed()

RunWait(@COMSPEC & " /c For /f "usebackq tokens=2 delims=[]" %%i in (`ping -n 1 %computername%`) do set IPAddress=%%i & ping %IPAddress% & pause")

EndFunc

; Just idle around

While 1

Sleep(10)

Wend

-----

.. but, it gives me this error:

RunWait(@COMSPEC & " /c For /f "usebackq tokens=2 delims=[]" %%i in (`ping -n 1 %computername%`) do set IPAddress=%%i & ping %IPAddress% & pause")

RunWait(@COMSPEC & " /c For /f "usebackq tokens^ ERROR

Error: Missing separator character after keyword.

Can I modify this script to do what I want or, do you guys/gals have a better script that works?

Thanks,

Mark

Link to comment
Share on other sites

Ipconfig shows your own ip. My ping yourself? There is a macro for your IP and a func called Ping

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

If you´r MsgBox realy looked like this:

MsgBox(32,"","Tims(ms) : " & $ping)

There is no possability of getting "? and Tims(ms) : 1" as text.

Only "Tims(ms) : 1"

What means the ping to your computer takes 1 ms or <1ms

OK. The problem with the current script is that even when my Local Area Connection is Disabled, it returns thae same value.

What I was hoping for is that a DOS window would open (Or the one that pops up now is OK, as long as it has all data in it), ipconfig is run, then script takes the resulting "IP Address" and pings that address, showing the results.

Basically, I am trying to automate these steps: Open command window, run ipconfig, determine the IP Address and type ping "the IP Address" and hit Enter.

Mark

Link to comment
Share on other sites

As i just did something similar here a examplecode

Look at helpfile for StdoutRead

CODE

If $Command = "GET:ALL" Then

$foo = Run(@ComSpec & " /c " & 'volumeline.exe ' & $Command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While ProcessExists($foo)

Sleep(50)

WEnd

$line = StdoutRead($foo)

$line = StringStripCR($line)

$line = StringSplit($line, @LF)

GetAllInformationfromVolumeline($line)

$errorline = StderrRead($foo)

If $errorline <> "" Then MsgBox(0, "STDERR read:", $errorline)

EndIf

Link to comment
Share on other sites

As i just did something similar here a examplecode

Look at helpfile for StdoutRead

CODE

If $Command = "GET:ALL" Then

$foo = Run(@ComSpec & " /c " & 'volumeline.exe ' & $Command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While ProcessExists($foo)

Sleep(50)

WEnd

$line = StdoutRead($foo)

$line = StringStripCR($line)

$line = StringSplit($line, @LF)

GetAllInformationfromVolumeline($line)

$errorline = StderrRead($foo)

If $errorline <> "" Then MsgBox(0, "STDERR read:", $errorline)

EndIf

-----

Line 1 causes this error:

If $Command="GET:ALL" Then

If ^ ERROR

Error: Variable used without being declared.

-----

Any ideas? I am running

SciTE4AutoIt3

Version 1.75

Nov 2007

Mark

Link to comment
Share on other sites

okay.. "examplecode" was the wrong word.

"Here is a part of my program that does what you want to do: Look at StdoutRead in the Helpfile "

-----

I have been going nuts since your last post trying to find/modify scripts to get a script that will find my PC's IP Address, then ping it.

OK, I got scipts to output my computer's IP Address to a text file or message box. The problem is, how can I use the data/ variable/string in a command like "ping [ipaddress]". I cannot ping a variable, it seems, I get errors.

How can I take the value from say, notepad or the clipboard and import it into a dos command like ping [ip address]?

I haven't found anything on the web that adresses this. I guess nobody ever wants to ping their own IP Address- unless they manually type it in.

Please help me before I go comepletely mad :)

Mark

Link to comment
Share on other sites

LIMITER's code works fine on my machine to do all that you say you are trying to do, except what do you want to do visa vis ipconfig and your ip address? It seems like all you can do with ipconfig and an ip address is to release or renew a connection, not ping one.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

If you still want to use the output of the commandwindow.

Just do like this:

1. Get the Commandwindow text to a variable.

2. Trim/Split until you only got the IP adress left.

3. Go for something like this:

CODE
$ip = "127.0.0.1"

Run(@ComSpec & " /c " & 'ping ' & $ip, "", @SW_SHOW)

If you want to parse this information you have to use StdoutRead again

Link to comment
Share on other sites

If you still want to use the output of the commandwindow.

Just do like this:

1. Get the Commandwindow text to a variable.

2. Trim/Split until you only got the IP adress left.

3. Go for something like this:

CODE
$ip = "127.0.0.1"

Run(@ComSpec & " /c " & 'ping ' & $ip, "", @SW_SHOW)

If you want to parse this information you have to use StdoutRead again

Thanks. I actually got that far yesterday. I got the IP Address isolated and saved into a text file or printed in a message box.

Now, if I could take that address and pull it out of the text file/message box and put it into a command line then ping it, I'd be as happy as a pig in poop.

Thanks,

Mark

Link to comment
Share on other sites

I found the answer!!! Thanks to: http://www.experts-exchange.com/Networking...Q_22060380.html (I modified it slightly.)

This works in a bat file but, I would like to have it included in my Autoit file with all the other scripts I have.

Can you all help me make the correct changes to make it work in AutoIt?

-----

@echo off

if exist error.txt del error.txt >NUL

:pingtest

for /f "delims=" %%a in (pingme.txt) do call :PROCESS %%a

::wait 30 seconds before continuing

ping localhost -n 30 > NUL

goto :pingtest

:PROCESS

ping %1 -n 4

if ERRORLEVEL 1 goto IPERROR

echo.

echo.

echo.

echo Your IP: %1 works !

goto :eof

:IPERROR

echo IP: %1 is down at %time% >> error.txt

-----

Thanks,

Mark

Link to comment
Share on other sites

I wrote an app that does this and more.

You will have to customize these functions to suit your needs. I used certain vars (like $GUI_W", etc) that you will have to deal with, which are defined in my own GUI section.

I also used IP addresses for the local ISPs here in Panama (see Select Case).

You will also have to add your own INI file, define the keys for it, declare the vars, etc.

Here is the code that finds your router's IP, then your ISP's gateway IP. I have more code that tries to discover what the problem is if there is no connection to the router or to the gateway, but am not including it here for simplicity sake.

Func GetIPs ()
    $SplashMsg = "Finding IP addresses. Please wait ..."
    SplashTextOn("Internet Checker", $SplashMsg , ($DesktopHeight - $GUI_H), 50, ($DesktopWidth - $GUI_W - 300), ($DesktopHeight - $GUI_H + 100), 4, "", 9)
    
    ;Find router and gateway IPs.
    TraceRoute ($routerIP, $gatewayIP)
    
    ;Store IP values in Registry.
    IniWrite($IniFile, $IniSection, $Key1, $routerIP)
    IniWrite($IniFile, $IniSection, $Key2, $gatewayIP)
    
    ;Find ISP based on gateway address.
    Select
        Case StringInStr($gatewayIP, "10.100.107.")
            $ISP = "Adess Networks"
        
        Case StringInStr($gatewayIP, "10.100.110.")
            $ISP = "Adess Networks"
        
        Case StringInStr($gatewayIP, "10.10.0.")
            $ISP = "Wireless Internet Solutions"

        Case StringInStr($gatewayIP, "200.3.206.")
            $ISP = "MobilNet"

        Case StringInStr($gatewayIP, "10.11.32.")
            $ISP = "Si Wireless"

        Case Else
            $ISP = "Unknown ISP"
    EndSelect

    ;Set values in GUI.
    GUICtrlSetData($Value_Router, $routerIP)
    GUICtrlSetData($Value_Gateway, $gatewayIP)
    GUICtrlSetData($Label_ISP, $ISP)
    
    ;Splash off.
    SplashOff()

    MsgBox(0, "IP Addresses", "IP addresses have been updated and saved.")
    ;MsgBox(0, "Internet Checker","Internet Status: OK.")
EndFuncoÝ÷ Ù«­¢+ÙÕ¹QÉI½ÕÑ¡    åIÀÌØíɽÕÑÉ%@°   åIÀÌØíÑÝå%@¤($í%¹¥Ñ¥±¥éÙÉ¥±Ì¸($ÀÌØí=ÕÑÁÕÐôÅÕ½ÐìÅÕ½Ðì($ÀÌØíÁ½ÌÄôÀ($ÀÌØíÁ½ÌÈôÀ($ÀÌØíÁ½ÌÌôÀ($ÀÌØíÍÑÉ¥¹ÄôÅÕ½ÐìÅÕ½Ðì($ÀÌØíÍÑÉ¥¹ÈôÅÕ½ÐìÅÕ½Ðì($ÀÌØíÍÑÉ¥¹ÌôÅÕ½ÐìÅÕ½Ðì($ÀÌØíɽÕÑÉ%@ôÀ($ÀÌØíÑÝå%@ôÀ($($É¥½¸èÐI½ÕÑÈ%@($$ÀÌØíÁ¥ôIÕ¸¡
½µMÁµÀìÅÕ½Ðì½ÅÕ½ÐìµÀìÌäí¥Á½¹¥Ìäì°ÅÕ½ÐìÅÕ½Ðì°M]}!%°ÀÌØíMQII}
!%1¬ÀÌØíMQ=UQ}
!%1¤($%AɽÍÍ]¥Ñ
±½Í ÀÌØíÁ¥°ÄÀ¤ì]¥ÐÕÀѼÄÀͽ¹Ì¸($$ÀÌØí=ÕÑÁÕеÀìôMѽÕÑI ÀÌØíÁ¥¤ìMÙ½ÕÑÁÕи($$í5Í  ½à À°ÅÕ½Ðí=ÕÑÁÕÐè¥Á½¹¥ÅÕ½Ðì°ÀÌØí=ÕÑÁÕФ($$($$ÀÌØíIÍÕ±ÐôMÑÉ¥¹IáÀ ÀÌØí=ÕÑÁÕаÅÕ½ÐílÀ´åulÀ´åtýlÀ´åtü¹lÀ´åulÀ´åtýlÀ´åtü¹lÀ´åulÀ´åtýlÀ´åtü¹lÀ´åulÀ´åtýlÀ´åtüÅÕ½Ðì°Ì¤($%%ÉɽȱÐìÐìÀQ¡¸($$%5Í    ½à À°ÅÕ½Ðí%¹ÑɹÐ
¡­ÈèÉɽÈÈÅÕ½Ðì°ÅÕ½Ðí]¡½½ÁÌÌÌìAɽ±´½ÕÉÉÝ¥Ñ ¥Á½¹¥ÍÑÉ¥¹¸A±ÍÑÉ䥸¸ÅÕ½Ðì¤($$%á¥Ð($%¹%($$í5Í    ½à À°ÅÕ½ÐíQÉI½ÕÑèIÍÕ±ÐÅÕ½Ðì°ÀÌØíIÍÕ±ÑlÉt¤($$($$í
¡¬ÍÑÉ¥¹mɵ½ÙÁÉ¥½Ì°Ñ¡¸¹ÍÕɥХ̥¥Ñt¸($%¥´ÀÌØíàôMÑÉ¥¹IÁ± ÀÌØíIÍÕ±ÑlÉt°ÅÕ½Ðì¸ÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤($%%MÑÉ¥¹%Í¥¥Ð ÀÌØíà¤ôÀQ¡¸($$%5Í    ½à À°ÅÕ½Ðí%¹ÑɹÐ
¡­ÈÅÕ½Ðì°ÅÕ½Ðí]¡½½ÁÌÌÌìAɽ±´½ÕÉÉÝ¥Ñ ¥Á½¹¥ÍÑÉ¥¹¸A±ÍÑÉ䥸¸ÅÕ½Ðì¤($%¹%($$ÀÌØíɽÕÑÉ%@ôÀÌØíIÍÕ±ÑlÉtìÍÉ%@½Õ¹¥¸±¥Íи($$í5Í    ½à À°ÅÕ½ÐíI½ÕÑÈ%@ÅÕ½Ðì°ÀÌØíɽÕÑÉ%@¤($$($$íQÍÐѼµ­ÍÕɥн¹¹Ñ=,¸($$ÀÌØíQÍÐÄôMÑÉ¥¹%¹MÑÈ ÀÌØí=ÕÑÁÕаÅÕ½ÐíÉÅÕÍÐÑ¥µ½ÕÐÅÕ½Ðì¤($$ÀÌØíQÍÐÈôMÑÉ¥¹%¹MÑÈ ÀÌØí=ÕÑÁÕаÅÕ½ÐíÍÑ¥¹Ñ¥½¸¡½ÍÐչɡ±ÅÕ½Ðì¤($%%ÀÌØíQÍÐÄÐìÀ=HÀÌØíQÍÐÈÐìÀQ¡¸($$%MÁ±Í¡= ¤($$%5Í  ½à À°ÅÕ½ÐíI½ÕÑÈAɽ±´ÅÕ½Ðì°ÅÕ½ÐíQ¡ÉÝÌÁɽ±´½¹¹Ñ¥¹Ñ¼å½ÕÈɽÕÑȸÅÕ½ÐìµÀì
I1µÀì|($$$ÅÕ½ÐíA±ÍÙÉ¥äѡХХÌÁ½Ýɽ¸¹½¹¹Ñ¸ÅÕ½ÐìµÀì
HµÀì|($$$ÅÕ½Ðí%å½ÔÕÍݥɱÍÌÁÑÈ°ÍÕɥи½¹¹ÐѼѡɽÕÑȸÅÕ½ÐìµÀì
HµÀì|($$$ÅÕ½ÐíQ¡¸ÑÉ䥸¸ÅÕ½Ðì¤($$%á¥Ð($%¹%($$í5Í ½à À°ÅÕ½ÐíQÉI½ÕÑèI½ÕÑÉ%@ÅÕ½Ðì°ÅÕ½ÐíɽÕÑÉ%@ôÅÕ½ÐìµÀìÀÌØíɽÕÑÉ%@¤($¹É¥½¸($($É¥½¸èÐÑÝä%@($$ÀÌØí=ÕÑÁÕÐôÅÕ½ÐìÅÕ½Ðì($$ÀÌØíÁ¥ôIÕ¸¡
½µMÁµÀìÅÕ½Ðì½ÅÕ½ÐìµÀìÌäíÑÉÉÐÝÝܹ½½±¹½´Ìäì°ÅÕ½ÐìÅÕ½Ðì°M]}!%°ÀÌØíMQII}
!%1¬ÀÌØíMQ=UQ}
!%1¤($%AɽÍÍ]¥Ñ
±½Í ÀÌØíÁ¥°ÄÀ¤ì]¥ÐÕÀѼÄÀͽ¹Ì¸($$ÀÌØí=ÕÑÁÕеÀìôMѽÕÑI ÀÌØíÁ¥¤ìMÙ½ÕÑÁÕи($$í5Í  ½à À°ÅÕ½ÐíQÉÉÐѼ½½±ÅÕ½Ðì°ÀÌØí=ÕÑÁÕФ($$($$íQÍÐѼµ­ÍÕɥн¹¹Ñ=,¸($$ÀÌØíQÍÐÄôÅÕ½ÐìÅÕ½Ðì($$ÀÌØíQÍÐÈôÅÕ½ÐìÅÕ½Ðì($$ÀÌØíQÍÐÄôMÑÉ¥¹%¹MÑÈ ÀÌØí=ÕÑÁÕаÅÕ½ÐíÉÅÕÍÐÑ¥µ½ÕÐÅÕ½Ðì¤($$ÀÌØíQÍÐÈôMÑÉ¥¹%¹MÑÈ ÀÌØí=ÕÑÁÕаÅÕ½ÐíÍÑ¥¹Ñ¥½¸¡½ÍÐչɡ±ÅÕ½Ðì¤($%%ÀÌØíQÍÐÄÐìÀ=HÀÌØíQÍÐÈÐìÀQ¡¸($$%MÁ±Í¡= ¤($$%5Í ½à À°ÅÕ½Ðí%¹ÑɹÐAɽ±´ÅÕ½Ðì°ÅÕ½ÐíQ¡ÉÝÌÁɽ±´½¹¹Ñ¥¹Ñ¼å½ÕÈÑÝä¸ÅÕ½ÐìµÀì
I1µÀì
I1µÀì|($$$ÅÕ½Ðí%¥Ð¥Ì½ä½ÈÉ¥¹¥¹°Ý¥Ðչѥ°ÝѡȱÉ̸ÅÕ½ÐìµÀì
I1µÀì|($$$ÅÕ½Ðí%å½ÔÕÍݥɱÍÌÁÑÈ°ÍÕɥи½¹¹ÐѼå½ÕÈɽÕÑÈ¥ÉÍиÅÕ½ÐìµÀì
I1µÀì|($$$ÅÕ½Ðí=Ñ¡ÉݥͰ¥Ð¥ÌÁ½ÍÍ¥±Ñ¡Ðå½ÕÈ%M@ÌäíÌÑÝä¥Ì½Ý¸¸ÅÕ½Ðì¤($$%á¥Ð($%¹%($$($$í¥¹ÑÝä%@ɽ´ÑÉÉи($$ÀÌØíIÍÕ±ÐôMÑÉ¥¹IáÀ ÀÌØí=ÕÑÁÕаÅÕ½ÐílÀ´åulÀ´åtýlÀ´åtü¹lÀ´åulÀ´åtýlÀ´åtü¹lÀ´åulÀ´åtýlÀ´åtü¹lÀ´åulÀ´åtýlÀ´åtüÅÕ½Ðì°Ì¤($%%ÉɽȱÐìÐìÀQ¡¸($$%5Í ½à À°ÅÕ½Ðí%¹ÑɹÐ
¡­ÈèÉɽÈÌÅÕ½Ðì°ÅÕ½Ðí]¡½½ÁÌÌÌìAɽ±´½ÕÉÉÝ¥Ñ ÑÝäÍÑÉ¥¹¸A±ÍÑÉ䥸¸ÅÕ½Ðì¤($$%á¥Ð($%¹%($$í5Í    ½à À°ÅÕ½ÐíQÉI½ÕÑèIÍÕ±ÐÅÕ½Ðì°ÀÌØíIÍÕ±ÑlÉt¤($$($$í¥¹Ý¡¥ %@ÉÍ̽µÌÑÈɽÕÑÈ%@ÉÍ̸($%½ÈÀÌØíàôÀQ¼U   ½Õ¹ ÀÌØíIÍձФ($$%%ÀÌØíIÍÕ±ÑlÀÌØíátôÀÌØíɽÕÑÉ%@Q¡¸($$$$ÀÌØíàôÀÌØíà¬ÄìU͹áÐ%@ÉÍ̸($$$$ÀÌØíÑÝå%@ôÀÌØíIÍÕ±ÑlÀÌØíát($$$$íMÁ±¥Ð%@¥¹Ñ¼½ÑÑÌ°Ñ¡¸ÕÍÅÕ½Ðì¸ÄÅÕ½Ðìй¸($$$$ÀÌØíÑÝå%A}ѵÀôMÑÉ¥¹MÁ±¥Ð ÀÌØíÑÝå%@°ÅÕ½Ðì¸ÅÕ½Ðì¤($$$$ÀÌØíÑÝå%@ôÀÌØíÑÝå%A}ѵÁlÅtµÀìÅÕ½Ðì¸ÅÕ½ÐìµÀìÀÌØíÑÝå%A}ѵÁlÉtµÀìÅÕ½Ðì¸ÅÕ½ÐìµÀìÀÌØíÑÝå%A}ѵÁlÍtµÀìÅÕ½Ðì¸ÄÅÕ½Ðì($$$%á¥Ñ1½½À($$%¹%($%9áÐ($$($$í
¡¬ÍÑÉ¥¹mɵ½ÙÁÉ¥½Ì°Ñ¡¸¹ÍÕɥХ̥¥Ñt¸($%¥´ÀÌØíàôMÑÉ¥¹IÁ± ÀÌØíÑÝå%@°ÅÕ½Ðì¸ÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤($%%MÑÉ¥¹%Í¥¥Ð ÀÌØíà¤ôÀQ¡¸($$%5Í ½à À°ÅÕ½Ðí%¹ÑɹÐ
¡­ÈÅÕ½Ðì°ÅÕ½Ðí]¡½½ÁÌÌÌìAɽ±´½ÕÉÉÝ¥Ñ ÑÝäÍÑÉ¥¹¸A±ÍÑÉ䥸¸ÅÕ½Ðì¤($%¹%($$í5Í  ½à À°ÅÕ½ÐíÑÝä%@ÅÕ½Ðì°ÀÌØíÑÝå%@¤($¹É¥½¸($$(%IÑÕɸÀÌØíɽÕÑÉ%@µÀìÀÌØíÑÝå%@)¹Õ¹

Dick

I found the answer!!! Thanks to: http://www.experts-exchange.com/Networking...Q_22060380.html (I modified it slightly.)

This works in a bat file but, I would like to have it included in my Autoit file with all the other scripts I have.

Can you all help me make the correct changes to make it work in AutoIt?

-----

@echo off

if exist error.txt del error.txt >NUL

:pingtest

for /f "delims=" %%a in (pingme.txt) do call :PROCESS %%a

::wait 30 seconds before continuing

ping localhost -n 30 > NUL

goto :pingtest

:PROCESS

ping %1 -n 4

if ERRORLEVEL 1 goto IPERROR

echo.

echo.

echo.

echo Your IP: %1 works !

goto :eof

:IPERROR

echo IP: %1 is down at %time% >> error.txt

-----

Thanks,

Mark

Link to comment
Share on other sites

  • 2 years later...

Find default gateways of connected adapters and ping each 50 times, then write the output to a file:

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$concat = ""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
    For $objItem In $colItems
        $strDefaultIPGateway = $objItem.DefaultIPGateway(0)

        $concat = $objItem.Caption & @CRLF & "Default Gateway: " & $strDefaultIPGateway & @CRLF
        $loops = 1
        $total = ""
        While $loops <= 50
            $ping = Ping($strDefaultIPGateway, 1200)
            $total = $total + $ping
            $concat = $concat & "ping " & $loops & ": " & $ping & " ms" & @CRLF
            $loops = $loops + 1
        WEnd
        $concat = $concat & "Average " & $total / $loops & " ms" & @CRLF
        $tempfile = @ScriptDir & "\" & $objItem.Caption & ".txt"
        $file = FileOpen($tempfile, 1)
        FileWrite($file, $concat)
        FileClose($file)

        ;If MsgBox(1, "WMI Output", $concat) = 2 Then ExitLoop
        $concat = ""
    Next
Else
    MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration")
EndIf
Link to comment
Share on other sites

  • 2 months later...

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...