Sign in to follow this  
Followers 0
hshds

Get the WAN IP through Telenet or an other method

5 posts in this topic

Is there any way to get my WAN IP through Telenet or an other method directly from my router, without "leaving" the LAN?

Some Internet providers change the public IP at non-regular time about once a day, and my application hangs after the IP changes. Therefore i must check every minute to eventually restart it.

Until today i've done it through

1. GetIP(), and also through

2. ping myname.dyndns.org -n 1 > c:\wanipa.txt

but this places unnecessary load on the external Internet servers. Also it is not optimal to open and close the command window every minute (more than 10000 times per day).

I would like to do something like

func _TelnetToIPWithPW($ip, $pw) ;; ip = address or name

local $pid

if not winExists(@comSpec) then ;; "E:\WINNT\system32\cmd.exe"

$pid = run(@comSpec & " /c telnet " & $ip, "", @sw_show)

while not winExists(@comSpec)

sleep(50)

wEnd

winActivate(@comSpec)

winWaitActive(@comSpec)

send($pw)

sleep(50)

send("{ENTER}")

sleep(200)

endIf

endFunc

func _TelnetGetLog()

local $text

winActivate(@comSpec)

winWaitActive(@comSpec)

; controlSend(@comSpec, "", "ConsoleWindowClass", "log -c", 0) ;doesn't work

send("log -c") ;; get the router's call log

sleep(1000)

send("{ENTER}")

sleep(400)

for $i = 1 to 10 ;; a must, here

send("{SPACE}") ;; more, more, ..

sleep(50)

next

sleep(100)

send("!{SPACE}") ;; alt-<space>, window menu

sleep(200)

send("es") ;; &edit>>&select all

sleep(400)

send("{ENTER}") ;; copy

sleep(400)

$text = clipGet()

sleep(200)

send("exit")

sleep(100)

send("{ENTER}")

sleep(400)

return $text

endFunc

func _TelnetGetWANIPA()

local $text, $len, $wanipa, _

$startstring, $stopstring, $startindex, $stopindex

$text = _TelnetGetLog()

$startstring = "Own IP Address :"

$stopstring = "Peer IP Address :"

$len = stringLen($startstring)

$startindex = stringInStr($text, $startstring, 0, -1) + $len

$stopindex = stringInStr($text, $stopstring, 0, -1)

$wanipa = stringMid($text, $startindex, $stopindex - $startindex - 1)

$wanipa = stringStripWS($wanipa, 1 + 2) ;; strip leading & trailing WS

; msgBox(0, "_TelnetGetWANIPA() | len", $wanipa & " | " & stringLen($wanipa))

return $wanipa

endFunc

but in this case it seems i must communicate with an "active/open" command window and use Send() instead of ControlSend(), which does not work.

Could anyone help, please?

Share this post


Link to post
Share on other sites



my linksys router gives me my ip in the status page:

so i could just get the source of it.

i my case it would be:

http://username:password@192.168.1.1/Status.htm

but your company probly doesnt have a webinterface.


My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

my linksys router gives me my ip in the status page:

so i could just get the source of it.

i my case it would be:

http://username:password@192.168.1.1/Status.htm

but your company probly doesnt have a webinterface.

Many thanks for your reply, wOuter.

The problem persists. At my PC with W2K this method seems to not work. I have changed from empty user name to a non-empty one and tried your method in the following variants:

1. http://username:password@192.168.1.1/doc/online.sht

2. http://:password@192.168.1.1/doc/online.sht

3. http://password@192.168.1.1/doc/online.sht

but none of these get me the wanted page, they simply make the IE browser to stay working.

When i enter http://192.168.1.1/doc/online.sht (without credentials), i first get a dialog to enter my user name and password befor i get the page, but this dialog is exactly what i don't want.

Is there eventually a way to escape or suppress the interactive credentials dialog?

Share this post


Link to post
Share on other sites

Have you tried entering the correct username and password configured in the router on your way into the correct screen with a second, intermediary screen? This would possibly be more acceptable than suppressing the security on the router.

Share this post


Link to post
Share on other sites

This is old code i have from the forms, forgot where i got it

;---------------------------------------------------------------
;                  Find WAN iP-adresse
;---------------------------------------------------------------
$INI = @HomeDrive & "myip.ini"
If FileExists($INI) = 0 Then
    IniWrite($INI, "URL", "1", "dynupdate.no-ip.com")
    IniWrite($INI, "URL", "2", "www.bpftpserver.com")
    IniWrite($INI, "URL", "3", "www.minasithil.org")
    IniWrite($INI, "URL", "URLS", "3")
    
EndIf

$POS = 0
$IP = 0
$URLS = IniRead($INI, "URL", "URLS", "")

For $I = 1 To $URLS
    FileDelete(@HomeDrive & $POS + 1 & ".htm")
Next

While $POS < $URLS
    FileDelete(@HomeDrive & $POS - 1 & ".htm")
    $POS = $POS + 1
    $IPTMP = @HomeDrive & $POS & ".htm"
    $URL = IniRead($INI, "URL", $POS, "")
    $IP = InetGet("http://" & $URL & "/ip.php", $IPTMP)
    $FS = FileGetSize($IPTMP)
    
    
    If FileExists($IPTMP) = 0 Then ContinueLoop
    If $FS > 16 Then
        ContinueLoop
    Else
        If $FS < 8 Then ContinueLoop
    EndIf
    If $FS <= 16 Then ExitLoop
    
WEnd
$FILE = FileOpen($IPTMP, 0)
$LINE = FileReadLine($FILE)


If $FILE = -1 Then
    $LINE = "Error when looking up IP. Maybe you're offline?"
EndIf

FileClose($FILE)
FileDelete($IPTMP)
FileDelete($INI)

MsgBox(0, "", "WAN IP-address: " & $LINE)

Share this post


Link to post
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
Sign in to follow this  
Followers 0