daonlyfreez
Joined: 16 Mar 2005 Posts: 949 Location: Berlin
|
Posted: Tue Mar 02, 2010 4:11 pm Post subject: Renew External IP - Restart Router |
|
|
A very simple script to renew your external IP/restart your router.
This one is specifically for my router, so you need to adapt, and not all routers will work.
I got the information needed from:
- http://www.paehl.de/reconnect/
- JDownloader, it has an internal database for routers (Tab "Settings" -> TreeView Modules:Reconnection > Button "Select router")
You need to find your router's curl command lines on the site mentioned, or study the code from JDownloader, and adapt the script.
Issue: If the router uses cookies, so if the curl command-line from paehl's site contains -c "cookies.txt", you cannot use this script. Use curl/libcurl itself instead.
I used mostly code from SKAN. See source for links.
HTH
| Code: | /*
A very simple script to renew your external IP/restart your router.
This one is specifically for my router, so you need to adapt, and not all routers will work.
I got the information needed from:
- http://www.paehl.de/reconnect/
- JDownloader (http://jdownloader.org/), it has an internal database for routers (Tab "Settings" -> TreeView Modules:Reconnection > Button "Select router")
You need to find your router's curl command lines on the site mentioned, or study the code from JDownloader, and adapt the script.
Issue: If the router uses cookies, so if the curl command-line from paehl's site contains -c "cookies.txt", you cannot use this script. Use curl/libcurl itself instead.
*/
RouterIP := "192.168.2.1" ; use actual IP of your router here
RouterPass := "yourpassword" ; the password
TrayTip, Renewing IP
, Your Network connection will temporarily be broken. Please wait...
beforeIP := GetExternalIP()
TrayTip, Renewing IP, Logging into router...
InternetFileRead(loginsrc
, "http://" . RouterIP . "/login.html?page=login&goto=/util_reset.htm&pws=" . RouterPass)
Sleep 1000
TrayTip, Renewing IP, Resetting router`nPlease wait...
InternetFileRead(resetsrc
, "http://" . RouterIP . "/util_reset.htm?page=system_reset&logout=2")
Sleep 10000
afterIP := GetExternalIP()
TrayTip, IP Renewed!, % "Old IP: " beforeIP "`nNew IP: " afterIP
Sleep 3000
; --------
GetExternalIP()
{
/* --- used sites in order of call
http://www.whatismyip.org/
http://checkip.dyndns.com/
http://www.formyip.com/
*/
; 1: ip only
URL := "http://www.whatismyip.org/"
If ( InternetFileRead( ipsrc, URL, 100, 100, "No-Progress" ) > 0 )
{
If IsValidIP(ipsrc)
Return ipsrc
}
; 2: <body>Current IP Address: xxx.xxx.xxx.xxx</body>
URL := "http://checkip.dyndns.com/"
If ( InternetFileRead( ipsrc, URL, 100, 100, "No-Progress" ) > 0 )
{
someip := StringBetween(ipsrc, "IP Address: ", "<")
If IsValidIP(someip)
Return someip
}
; 3: <title>My ip address is xxx.xxx.xxx.xxx The
URL := "http://www.formyip.com/"
If ( InternetFileRead( ipsrc, URL, 100, 100, "No-Progress" ) > 0 )
{
someip := StringBetween(ipsrc, "My ip address is ", " The")
If IsValidIP(someip)
Return someip
}
; fall through
Return "Error"
}
StringBetween(string, before, after)
{
fp := RegExMatch(string, "i)\Q" . before . "\E(.*?)\Q" . after . "\E", sb)
Return sb1
}
; SKAN: http://www.autohotkey.com/forum/post-178165.html#178165
IsValidIP(IP)
{
Return RegExMatch( IP, "^(25[0-5]|2[0-4][0-9]|[01]?[0-9]"
. "[0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
. "\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9"
. "]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" )
}
; SKAN: http://www.autohotkey.com/forum/topic45718.html
InternetFileRead( ByRef V, URL="", RB=0, bSz=1024, DLP="DLP", F=0x84000000 ) {
Static LIB="WININET\", QRL=16, CL="00000000000000", N=""
If ! DllCall( "GetModuleHandle", Str,"wininet.dll" )
DllCall( "LoadLibrary", Str,"wininet.dll" )
If ! hIO:=DllCall( LIB "InternetOpenA", Str,N, UInt,4, Str,N, Str,N, UInt,0 )
Return -1
If ! (( hIU:=DllCall( LIB "InternetOpenUrlA", UInt,hIO, Str,URL, Str,N, Int,0, UInt,F
, UInt,0 ) ) || ErrorLevel )
Return 0 - ( !DllCall( LIB "InternetCloseHandle", UInt,hIO ) ) - 2
If ! ( RB )
If ( SubStr(URL,1,4) = "ftp:" )
CL := DllCall( LIB "FtpGetFileSize", UInt,hIU, UIntP,0 )
Else If ! DllCall( LIB "HttpQueryInfoA", UInt,hIU, Int,5, Str,CL, UIntP,QRL, UInt,0 )
Return 0 - ( !DllCall( LIB "InternetCloseHandle", UInt,hIU ) )
- ( !DllCall( LIB "InternetCloseHandle", UInt,hIO ) ) - 4
VarSetCapacity( V,64 ), VarSetCapacity( V,0 )
SplitPath, URL, FN,,,, DN
FN:=(FN ? FN : DN), CL:=(RB ? RB : CL), VarSetCapacity( V,CL,32 ), P:=&V,
B:=(bSz>CL ? CL : bSz), TtlB:=0, LP := RB ? "Unknown" : CL, %DLP%( True,CL,FN )
Loop {
If ( DllCall( LIB "InternetReadFile", UInt,hIU, UInt,P, UInt,B, UIntP,R ) && !R )
Break
P:=(P+R), TtlB:=(TtlB+R), RemB:=(CL-TtlB), B:=(RemB<B ? RemB : B), %DLP%( TtlB,LP )
Sleep -1
} TtlB<>CL ? VarSetCapacity( T,TtlB ) DllCall( "RtlMoveMemory", Str,T, Str,V, UInt,TtlB )
. VarSetCapacity( V,0 ) . VarSetCapacity( V,TtlB,32 ) . DllCall( "RtlMoveMemory", Str,V
, Str,T, UInt,TtlB ) . %DLP%( TtlB, TtlB ) : N
If ( !DllCall( LIB "InternetCloseHandle", UInt,hIU ) )
+ ( !DllCall( LIB "InternetCloseHandle", UInt,hIO ) )
Return -6
Return, VarSetCapacity(V)+((ErrorLevel:=(RB>0 && TtlB<RB)||(RB=0 && TtlB=CL) ? 0 : 1)<<64)
} |
_________________
mirror 1 • mirror 2 • mirror 3 • ahk4.me • PM or  |
|