If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Rate Thread | Display Modes |
#16
|
|||
|
|||
Introducing a variable into the ping command
On Tue, 23 Jan 2018 19:41:11 -0800, Mike Easter
wrote: Nil wrote: An alternative utility is Curl. I like curl icanhazip.com in linux. The WAN IP result is 'clean' and free of any html. Nice find. That's about as clean as anything I've seen. # curl icanhazip.com 170.22.86.205 Or this, to see a little more about what's happening: # curl -v icanhazip.com * About to connect() to icanhazip.com port 80 (#0) * Trying 69.162.69.148... connected * Connected to icanhazip.com (69.162.69.148) port 80 (#0) GET / HTTP/1.1 User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/1.0.1l zlib/1.2.3 libidn/1.18 Host: icanhazip.com Accept: */* HTTP/1.1 200 OK Server: nginx Date: Wed, 24 Jan 2018 05:14:57 GMT Content-Type: text/plain; charset=UTF-8 Content-Length: 15 Connection: close X-SECURITY: This site DOES NOT distribute malware. Get the facts. https://goo.gl/1FhVpg X-RTFM: Learn about this site at http://bit.ly/icanhazip-faq and do not abuse the service. Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET 170.22.86.205 * Closing connection #0 -- Char Jackson |
Ads |
#17
|
|||
|
|||
Introducing a variable into the ping command
Of recent note Char Jackson wrote:
Nice find. That's about as clean as anything I've seen. # curl icanhazip.com 170.22.86.205 What I like about the curl is that it will be unambiguous that the network changed. 1) On network 1, the curl will return the network 1 IP address. 2) If that network socket stays constant, you're kosher. 3) But if the network drops back, accidentally, to your ISP... 4) Then the curl "should" show a *different* IP address instantly. Right? If so, then using curl should be enough to tell that the network 1 failed, dropping you back to your ISP. Right? Now the trick will be to get "curl" working on Windows. https://stackoverflow.com/questions/9507353/how-do-i-install-set-up-and-use-curl-on-windows#16216825 https://thecustomizewindows.com/2012/07/installing-curl-in-windows-to-run-curl-commands-natively/ |
#18
|
|||
|
|||
Introducing a variable into the ping command
Of recent note Timofei Krasniqi wrote:
I found, in testing, a huge flaw in the Nirsoft method! The "socket" for the pinger method hangs, which is what you want! http://i.cubeupload.com/Uk2KfP.jpg But, for whatever reason, Nirsoft just picks up with the "new" socket! http://i.cubeupload.com/IZ7UPh.jpg Unless that propensity to pick up where Nirsoft left off is able to be turned off, it makes the NirSoft method useless because it's "reliable". What we want is a tool to detect the network change! Oh oh. I may have made a mistake above. I really do not understand this "socket" stuff, and, yes, I've googled it and I have never found a simple explanation that I really understand. Anyway, it appears the only reason the ping hung up was because I highlighted a line so I could tell if it was moving, and *that* hung the ping up, not the socket. So, both the ping and Nirsoft are "too good" in that they "recover" from a lost socket connection, which isn't what I want. When the network *changes*, I want the ping or Nirsoft to fail. The ping just happily pings using the *new* socket, which isn't what I want. At least Nirsoft, which also starts using the *new* socket, shows a momentary *red spot* if you're lucky, where it skips a connection but all that depends on the frequency of test. Darn. Maybe the "curl" of "icanhazip.com" on Windows is better because it would at least report a *different IP address* when the connection changes. But where is the tutorial to get curl working on Windows? |
#19
|
|||
|
|||
Introducing a variable into the ping command
Of recent note Timofei Krasniqi wrote:
Now the trick will be to get "curl" working on Windows. To give back, I documented it working up to steps #14 and #15 below. In step 14, the cmd window goes away when we run "curler.bat". What do we need to add to JJ's batch file to keep the cmd window open? 1) Visit the curl download-wizard page: https://curl.haxx.se/dlwiz/ 2) Select the "Type of Package: curl executable" 3) Select the "Operating System: Win64" 4) Select for "What Flavour: Generic" 5) Select which "Win64 version: Any" 6) Select for "What CPU: x86_64" 7) You end up with the download link: https://bintray.com/artifact/downloa...win64-mingw.7z 8) Unpack "curl-7.57.0-win64-mingw.7z" to ".\curl-7.57.0-win64-mingw\" 9) Test it quickly: Start Run %windir%\system32\cmd.exe /K "C:\path\curl\bin\curl.exe icanhazip.com" 10) Make a curl.lnk shortcut to ".\curl-7.57.0-win64-mingw\bin\curl.exe" 11) Move that shortcut to Start Programs Scripts curl.lnk 12) Edit the shortcut target from "C:\path\curl\bin\curl.exe" to Target = %windir%\system32\cmd.exe /K "C:\path\curl\bin\curl.exe icanhazip.com" Comment = Reports current WAN IP address 13) Test that shortcut: Start Programs Scripts curl.lnk 14) Create a batch file "C:\path\curl\bin\curler.bat" (based on JJ's previous suggestion) REM Run the curl command to get your IP address @echo off setlocal set n=%1 if "%n%" == "" ( set /p "n=Enter host/IP (leave empty for icanhazip.com): " ) if "%n%" == "" set n=icanhazip.com curl %n% HELP: This works - but the window disappears instantly. How do we make the window remain? 15) Create a new "App Path" 'String' key so that "Start Run" works. Start Run curler OK HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\curler.exe (Default) = C:\path\curl\bin\curler.bat Note that "curler.exe" is just an arbitrary name which must end with ".exe" where an actual file "curler.exe" should not actually exist. In step 14 above, the command window goes away when we run "curler.bat". What do we need to add to JJ's batch file to keep the cmd window open? |
#20
|
|||
|
|||
Introducing a variable into the ping command
On 24 Jan 2018, Timofei Krasniqi wrote
in alt.windows7.general: In step 14 above, the command window goes away when we run "curler.bat". What do we need to add to JJ's batch file to keep the cmd window open? PAUSE |
#21
|
|||
|
|||
Introducing a variable into the ping command
On 23 Jan 2018, Mike Easter wrote in
alt.windows7.general: I like curl icanhazip.com in linux. The WAN IP result is 'clean' and free of any html. I like that, too! You can get both the IPv4 and 6 addresses. Cool! Thanks for the tip. I believe there are Win32 & Win64 available as well. https://curl.haxx.se/download.html |
#22
|
|||
|
|||
Introducing a variable into the ping command
Of recent note Nil wrote:
In step 14 above, the command window goes away when we run "curler.bat". What do we need to add to JJ's batch file to keep the cmd window open? PAUSE Thank you for that help. Inserting a trailing "pause" worked perfectly. Only one thing left to mimic the original "ping" question with "curl" which is to loop it forever (which "ping -t" did). I'll look for the "-t" option in the copious results from: curl.exe --help curl.help.txt curl.exe --manual curl.man.txt Huh? I just went through every line of curl.help.txt and there's no option to keep doing it. That's strange. Let me look at the manpage. Hmmm.... the "-retry" seems to be the closest analog to "pint -t" but the retry option in curl seems to only be for errors. Did I miss something? Does curl have the equivalent of a "ping -t" which repeats the command? |
#23
|
|||
|
|||
Introducing a variable into the ping command
On Wed, 24 Jan 2018 16:48:47 +0000 (UTC), Timofei Krasniqi
wrote: Only one thing left to mimic the original "ping" question with "curl" which is to loop it forever (which "ping -t" did). I'll look for the "-t" option in the copious results from: curl.exe --help curl.help.txt curl.exe --manual curl.man.txt Huh? I just went through every line of curl.help.txt and there's no option to keep doing it. That's strange. Let me look at the manpage. Hmmm.... the "-retry" seems to be the closest analog to "pint -t" but the retry option in curl seems to only be for errors. Did I miss something? Does curl have the equivalent of a "ping -t" which repeats the command? On your Linux host, you could wrap it in 'watch': watch -n60 curl icanhazip.com -- Char Jackson |
#24
|
|||
|
|||
Introducing a variable into the ping command
Of recent note Char Jackson wrote:
On your Linux host, you could wrap it in 'watch': watch -n60 curl icanhazip.com Linux is always easy compared to Windows for batch scripting. This should work though. https://stackoverflow.com/questions/2591758/batch-script-loop#2591782 This was tested to work, where it will report the IP address every second for 100 seconds when I hit "Start Run curler OK". @echo off goto actual set /a loopcount=0 :actual set /a loopcount=%loopcount% + 1 C:\path\curl\bin\curl.exe icanhazip.com timeout 1 /nobreaknul if %loopcount%== 100 goto stop goto actual :stop exit |
#25
|
|||
|
|||
Introducing a variable into the ping command
Of recent note Timofei Krasniqi wrote:
This was tested to work, where it will report the IP address every second for 100 seconds when I hit "Start Run curler OK". Slowly I'm realizing, belatedly, that the right approach is something like this flow chart. 1. Save your original ISP IP address (which we'll call OLD_IP) 2. Switch networks and run curl and save the NEW_IP 3. Keep running curl, comparing the IP address 4. The moment the IP address changes - you ring an alarm |
#26
|
|||
|
|||
Introducing a variable into the ping command
On Thu, 25 Jan 2018 02:01:35 +0000 (UTC), Timofei Krasniqi
wrote: This was tested to work, where it will report the IP address every second I'd be hesitant to hit it every second because of the note (in a header) from the site admin: X-RTFM: Learn about this site at http://bit.ly/icanhazip-faq and do not abuse the service. I don't know what he considers abuse. At least you're stopping after a finite number of hits. for 100 seconds when I hit "Start Run curler OK". @echo off goto actual set /a loopcount=0 :actual set /a loopcount=%loopcount% + 1 C:\path\curl\bin\curl.exe icanhazip.com timeout 1 /nobreaknul if %loopcount%== 100 goto stop goto actual :stop exit I think I'd swap these two lines. goto actual set /a loopcount=0 Or better yet, just remove that instance of "goto actual". It looks superfluous. -- Char Jackson |
#27
|
|||
|
|||
Introducing a variable into the ping command
Of recent note Char Jackson wrote:
I think I'd swap these two lines. goto actual set /a loopcount=0 Thanks for that advice, as that seems to work fine. @echo off REM curler.bat {Returns IP address to doublecheck network status} REM WIP MUST = add a *compare* of the NEW_IP with the OLD_IP & ring alarm REM WIP SHOULD = figure out how to put the time & the same line as IP REM WIP COULD = get a hours:minutes:seconds time stamp REM goto actual set /a loopcount=0 goto actual :actual set /a loopcount=%loopcount% + 1 time /T C:\apps\browser\curl\bin\curl.exe icanhazip.com timeout 1 /nobreaknul goto actual if %loopcount%== 100 goto stop :stop exit Or better yet, just remove that instance of "goto actual". It looks superfluous. Thanks for following the logic, as I don't really understand this stuff. That works fine too! @echo off REM curler.bat {Returns IP address to doublecheck network status} REM WIP MUST = add a *compare* of the NEW_IP with the OLD_IP & ring alarm REM WIP SHOULD = figure out how to put the time & the same line as IP REM WIP COULD = get a hours:minutes:seconds time stamp REM goto actual set /a loopcount=0 :actual set /a loopcount=%loopcount% + 1 time /T C:\apps\browser\curl\bin\curl.exe icanhazip.com timeout 1 /nobreaknul goto actual if %loopcount%== 100 goto stop :stop exit |
#28
|
|||
|
|||
Introducing a variable into the ping command
On Thu, 25 Jan 2018 14:55:45 +0000 (UTC), Timofei Krasniqi
wrote: Of recent note Char Jackson wrote: I think I'd swap these two lines. goto actual set /a loopcount=0 Thanks for that advice, as that seems to work fine. @echo off REM curler.bat {Returns IP address to doublecheck network status} REM WIP MUST = add a *compare* of the NEW_IP with the OLD_IP & ring alarm REM WIP SHOULD = figure out how to put the time & the same line as IP REM WIP COULD = get a hours:minutes:seconds time stamp REM goto actual set /a loopcount=0 goto actual :actual set /a loopcount=%loopcount% + 1 time /T C:\apps\browser\curl\bin\curl.exe icanhazip.com timeout 1 /nobreaknul goto actual if %loopcount%== 100 goto stop :stop exit Or better yet, just remove that instance of "goto actual". It looks superfluous. Thanks for following the logic, as I don't really understand this stuff. That works fine too! @echo off REM curler.bat {Returns IP address to doublecheck network status} REM WIP MUST = add a *compare* of the NEW_IP with the OLD_IP & ring alarm REM WIP SHOULD = figure out how to put the time & the same line as IP REM WIP COULD = get a hours:minutes:seconds time stamp REM goto actual set /a loopcount=0 :actual set /a loopcount=%loopcount% + 1 time /T C:\apps\browser\curl\bin\curl.exe icanhazip.com timeout 1 /nobreaknul goto actual if %loopcount%== 100 goto stop :stop exit Looks like it'll loop forever now. Somehow, these two lines got swapped with each other. They need to be in the opposite order so that you check the value of the variable (and optionally skip to ":stop" before jumping back to the top at ":actual". goto actual if %loopcount%== 100 goto stop -- Char Jackson |
#29
|
|||
|
|||
Introducing a variable into the ping command
On 25 Jan 2018, Char Jackson wrote in
alt.windows7.general: I'd be hesitant to hit it every second because of the note (in a header) from the site admin: X-RTFM: Learn about this site at http://bit.ly/icanhazip-faq and do not abuse the service. I don't know what he considers abuse. At least you're stopping after a finite number of hits. Yes, Please, OP, don't hammer his site like that. He's doing us all a favor, one which I am now taking advantage of once a day. Hitting a web site every second starts to look like a DOS attack and would NOT be appreciated by anyone. He will be able to block your requests but it will still affect his service negatively. |
#30
|
|||
|
|||
Introducing a variable into the ping command
On Thu, 25 Jan 2018 21:58:26 -0500, Nil
wrote: On 25 Jan 2018, Char Jackson wrote in alt.windows7.general: I'd be hesitant to hit it every second because of the note (in a header) from the site admin: X-RTFM: Learn about this site at http://bit.ly/icanhazip-faq and do not abuse the service. I don't know what he considers abuse. At least you're stopping after a finite number of hits. Yes, Please, OP, don't hammer his site like that. He's doing us all a favor, one which I am now taking advantage of once a day. Hitting a web site every second starts to look like a DOS attack and would NOT be appreciated by anyone. He will be able to block your requests but it will still affect his service negatively. "This is why we can't have nice things." :-) -- Char Jackson |
|
Thread Tools | |
Display Modes | Rate This Thread |
|
|