Page 1 of 1 1
Topic Options
#128159 - 2004-10-20 08:53 AM Extrenal IP address
guytje Offline
Fresh Scripter

Registered: 2004-10-15
Posts: 7
Does somebody know how to get via a kix-script the external IP address if you are using a router ?

The IP-address you are using on the net.

Many thanks.

Top
#128160 - 2004-10-20 11:43 AM Re: Extrenal IP address
Cybex Offline
Getting the hang of it
*****

Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
What type of router? Make and model...
If your talking a SOHO router is it set for DHCP or static IP on the WAN side?
_________________________
Common sense isn't so common.

Top
#128161 - 2004-10-20 12:43 PM Re: Extrenal IP address
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Do you mean the address of the router, i.e. the gateway?

If so, look at EnumIPInfo() for one method - you will want to retrieve type "3".

For example:
Code:
"Default gateway: "+EnupIPInfo(0,3)+@CRLF



If you want to know the routers WAN ip address, you will need to resort to SNMP or scripted login to the router.

Tracert may also give you the information you require, for example:
Code:
c:\> tracert www.microsoft.com



Explain a little bit more about what you are looking for, and why.

Top
#128162 - 2004-10-20 12:44 PM Re: Extrenal IP address
Cybex Offline
Getting the hang of it
*****

Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
There are website that show you the IP address that you appear to be coming from. Like... My IP
This is ugly but if you don't want to rely on the accuracy of someone else's website you could try something along these line to pull the data from the router.
I was able to pull this from my linksys router and I see the WAN IP.
Code:
$IE = CreateObject("internetexplorer.application")

$IE.Visible = 1
$IE.Navigate("http://192.168.1.1")
$IE = 0

SendKeys("{TAB}{TAB}passwordhere{ENTER}")
SendKeys("~FA")
SendKeys("c:\ip.htm")
SendKeys("{TAB}{TAB}{ENTER}")
SendKeys("~FC")


I tried to use the ReadHTML() function but I was unable to pass the authentication info.
You could then parse out the WAN IP from the IP.HTM file.

I know this is a nasty way of doing this but in the end you are going to have to read the IP in from an external source like a webpage, DNS, or something. The only other option I can think of is to interface directly with the memory on the router and issue commands directly against the firmware to pull the info. Best I could come up with after just crawling out of bed. Maybe something better will come to me after my brain wakes up.


Edited by Cybex (2004-10-20 01:17 PM)
_________________________
Common sense isn't so common.

Top
#128163 - 2004-10-20 03:21 PM Re: Extrenal IP address
guytje Offline
Fresh Scripter

Registered: 2004-10-15
Posts: 7
Dear Richard,

I would like to know my external IP address. That's the address, I have received from my ISP. (via internet explorer, you can retrieve it via http://www.showmyip.com) Due to the fact that I'm connected with the internet via a router, I can't take the IP address of the computer because it's a local one.

The reason why I would like to know is, I would like to build a program which is informing me when my external IP address is changed.

Thanks,

Guy

Top
#128164 - 2004-10-20 03:24 PM Re: Extrenal IP address
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I use www.ipchicken.com
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128165 - 2004-10-20 03:41 PM Re: Extrenal IP address
guytje Offline
Fresh Scripter

Registered: 2004-10-15
Posts: 7
Les,

Ok, you use www.ipchicken.com, but can you integrate this in a kix-script which is checking when an external address is changing.

Guy

Top
#128166 - 2004-10-20 03:41 PM Re: Extrenal IP address
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
In that case, the options (in my personal order of preference) would be:
  • SNMP query
  • Automated router web based management query (as Cybex suggested)
  • Scripted telnet / ftp
  • Automated web IP query


What router are you using?

Top
#128167 - 2004-10-20 03:42 PM Re: Extrenal IP address
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Les,

Ok, you use www.ipchicken.com, but can you integrate this in a kix-script which is checking when an external address is changing.

Guy




Yes.

Top
#128168 - 2004-10-20 03:49 PM Re: Extrenal IP address
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
maybe wrong but isn't this ip-address shown in ipconfig /all ?
If so it should also be queryable with enumipinfo()

[edit: dang, a router ... k, got it, forget about my post]


Edited by Jochen (2004-10-20 03:52 PM)
_________________________



Top
#128169 - 2004-10-20 03:51 PM Re: Extrenal IP address
guytje Offline
Fresh Scripter

Registered: 2004-10-15
Posts: 7
Router is a SMCrouter type SMC7004BVR.

But then the script can only be used with this router. I'm more looking for a general script.

Top
#128170 - 2004-10-20 03:56 PM Re: Extrenal IP address
guytje Offline
Fresh Scripter

Registered: 2004-10-15
Posts: 7
Jochen,

No it isn't showing with the dos-command ipconfig /all, that's the problem.

Regards,

Guy

Top
#128171 - 2004-10-20 04:07 PM Re: Extrenal IP address
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
This is a simple demo which works with the www.ipchicken.com site.

It sometimes chokes as it is looking for an HTML "BOLD" command - if this isn't present on the page it returns an incorrect value.

You can use this with a bit of error checking, or if you can find a site which uses named objects on the page you should be able to get a cleaner result.

Code:
$=SetOption("WrapAtEOL","ON")
$=SetOption("ASCII","ON")

$oIE = CreateObject("internetexplorer.application")
$oIE.Visible = 0
$oIE.Navigate("www.ipchicken.com")
While $oIE.busy AND $oIE.readystate <> 4 AND @ERROR = 0 Loop
$oDoc=$oIE.document
$sHTML=$oDoc.body.innerHTML
$oIE.Quit()
$oIE = 0

; Strip out IP address.
$sIP=SubStr($sHTML,InStr($sHTML,'<B>')+3)
$sIP=Left($sIP,InStr($sIP,' ')-1)
$sIP ?


Top
#128172 - 2004-10-20 04:11 PM Re: Extrenal IP address
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
...even simpler (and more reliable) with the other site...
Code:
$=SetOption("WrapAtEOL","ON")
$=SetOption("ASCII","ON")

$oIE = CreateObject("internetexplorer.application")
$oIE.Visible = 0
$oIE.Navigate("http://checkip.dyndns.org/")
While $oIE.busy AND $oIE.readystate <> 4 AND @ERROR = 0 Loop
$oDoc=$oIE.document
$sHTML=$oDoc.body.innerText
$oIE.Quit()
$oIE = 0

; Strip IP Address
$sIP=SubStr($sHTML,InStr($sHTML,':')+2)
$sIP ?


Top
#128173 - 2004-10-20 05:22 PM Re: Extrenal IP address
guytje Offline
Fresh Scripter

Registered: 2004-10-15
Posts: 7
Richard,

It's working.

Many thanks.

Guy

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.066 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org