Welcome Guest.   Make a donation to an author on the site October 01, 2014, 09:29:50 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Free DonationCoder.com Member Kit: Submit Request.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Programatically determining your IP Address...  (Read 9060 times)
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« on: June 27, 2008, 11:40:17 AM »

So, I'm working on a little application that has a few random utilities for myself... I'm using CodeGear RAD Studio and wondering if someone could explain the logical process of how to determine my IP Address (locally and externally) programatically... Is there some DLL I could call or some system command that I could use... I know there are commands I could use in the command prompt for windows but I was wondering if there was any other way to do it... Help is appreciated much smiley
« Last Edit: June 27, 2008, 11:47:42 AM by Codebyte » Logged

CodeByter.com - http://www.codebyter.com
EĆ³in
Charter Member
***
Posts: 1,400


O'Callaghan

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: June 27, 2008, 12:40:00 PM »

Coincidentally I read a snippet about this recently. For local IP address check out GetAdaptersInfo API function.

For the external IP I think you need to look into using a webservice which reports its. For example http://checkip.dyndns.org/.
Logged

Interviewer: Is there anything you don't like?
Bjarne Stroustrup: Marketing hype as a substitute for technical argument. Thoughtless adherence to dogma. Pride in ignorance.
f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #2 on: June 27, 2008, 05:59:33 PM »

What EĆ³in said smiley - external IP address is a bit of a mess. You need to depend on an external resource, which may or may not be available... so be careful about depending on that functionality. Ie., if you need the external IP address for a server application or whatever, you should offer auto-detection as a feature, but still let the user specify it manually.
Logged

- carpe noctem
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: June 27, 2008, 06:45:54 PM »

so, here's a question... is implementing this "auto-detection" feature really difficult? Not too good with networking... Thanks for the reply's also smiley

EDIT: Because of my inexperience with networking, my original idea went a little something like this:

http://ip-address.cc/ shows you your external IP. I took a look at the page's source code and it seems as though your external IP address is always contained at the beginning of line 120. So, I know this might sound like an "odd" idea, but I was gonna have the executable grab the source code for the site listed above and do some simple string manipulation in order to grab the external IP address... Please tell me if I sound crazy?
« Last Edit: June 27, 2008, 06:52:49 PM by Codebyte » Logged

CodeByter.com - http://www.codebyter.com
f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #4 on: June 27, 2008, 07:06:06 PM »

Don't go for line numbers - read up on regular expressions smiley

You might want to find a few of those services, and try them in round-robin if the first one fails.
Logged

- carpe noctem
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: June 27, 2008, 07:40:24 PM »

kk, that will give me somewhere to start... Thanks alot f0dder! Also, is that auto-detection thing a tough implementation? I wouldnt know how to go about doing it...
Logged

CodeByter.com - http://www.codebyter.com
f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #6 on: June 27, 2008, 07:47:17 PM »

Doesn't have to be *that* tough - as long as you have libraries that handle HTTP connections and regular expressions.

Basically, fetch a page (for instance http://checkip.dyndns.org/ or http://ip-address.cc/), try to match the Regular Expression you have designed for scraping the IP, and if it succeeds - you have the IP. If you want to code everything by hand, it will be complex. But if you have HTTP and RegEx libraries, it's a pretty quick job.
Logged

- carpe noctem
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: June 27, 2008, 08:20:39 PM »

Now, only left to do is figure out how to grab a web page's source code programatically.... Once I get this done, ill upload a sample executable to see if the String routine will work correctly with different IP's...
Logged

CodeByter.com - http://www.codebyter.com
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #8 on: June 30, 2008, 12:02:07 AM »

k, here is a test run... This application should grab the source from http://checkip.dyndns.org/ and use a simple string manipulation to find your external IP address... Please post and let me know the results.

If this doesnt work for everyone thats tries it, im going to set up an algorithm to grab what looks like the ip from a few several sources and perform string manipulation on them all. At the end, ill compare results and come up with a score sheet to make an estimated guess at the most accurate IP address... For now, I simply need feedback on this one...

http://www.codebyter.com/...a/Programs/externalip.exe
Logged

CodeByter.com - http://www.codebyter.com
mouser
First Author
Administrator
*****
Posts: 33,433



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #9 on: June 30, 2008, 12:09:24 AM »

works well here.  thumbs up
Logged
lanux128
Global Moderator
*****
Posts: 6,102



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #10 on: June 30, 2008, 12:15:52 AM »

works for me too.. i checked the external IP address with eToolz and they matched!. thumbs up
Logged

wreckedcarzz
Charter Member
***
Posts: 1,620



Happy wolfie ^_^

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #11 on: June 30, 2008, 02:11:52 AM »

Works well here smiley

Question: Would it be possible to have it give your your IP when the form loads, instead of having to click the button? I could definitely use this program for when I host game servers behind my router, and having it show up automatically is just that much more convenient.
Logged

New website! With a fancy domain name and everything! *gasp*
http://www.wreckedcarzz.com/
cthorpe
Discount Coordinator
Supporting Member
**
Posts: 718


c++thorpe

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #12 on: June 30, 2008, 03:40:06 AM »

k, here is a test run... This application should grab the source from http://checkip.dyndns.org/ and use a simple string manipulation to find your external IP address... Please post and let me know the results.

Worked for me as well.
Logged
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #13 on: June 30, 2008, 08:47:55 AM »

Wreckedcarzz, Im working on an executable for you right now... Just woke up lol! Is there anything else you would like added to it?
Logged

CodeByter.com - http://www.codebyter.com
wr975
Charter Member
***
Posts: 369



View Profile Give some DonationCredits to this forum member
« Reply #14 on: June 30, 2008, 08:59:15 AM »

Now, only left to do is figure out how to grab a web page's source code programatically.... Once I get this done, ill upload a sample executable to see if the String routine will work correctly with different IP's...

Try this URL: http://www.netikus.net/show_ip.html

Just the IP. Nothing more (no source code to search).

Autohotkey example:
[copy or print]
UrlDownloadToFile,http://www.netikus.net/show_ip.html,%a_temp%\myip.txt
Fileread,IP,%a_temp%\myip.txt
msgbox,your IP is %ip%
Logged
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: June 30, 2008, 09:19:52 AM »

Good find! I was looking for one of those sites that would supply only the IP address! Anyways, WreckedCarzz: Here is your executable! smiley

http://www.codebyter.com/...a/Programs/externalip.exe
« Last Edit: June 30, 2008, 09:21:27 AM by Codebyte » Logged

CodeByter.com - http://www.codebyter.com
mediaguycouk
Supporting Member
**
Posts: 244


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #16 on: June 30, 2008, 09:36:52 AM »

Whatismyip.com also have a single line IP page for automation

http://www.whatismyip.com/automation/n09230945.asp
Logged

Learning C# - Graham Robinson
f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #17 on: June 30, 2008, 10:08:51 AM »

Whatismyip.com also have a single line IP page for automation

http://www.whatismyip.com/automation/n09230945.asp
Times out here...
Logged

- carpe noctem
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #18 on: June 30, 2008, 10:15:12 AM »

Times out here...
That's because they know you're a hacker and you'd manage to DOS them through that page tongue
smiley jk.. It's working here.
Logged

cranioscopical
Friend of the Site
Supporting Member
**
Posts: 4,170



see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #19 on: June 30, 2008, 10:22:34 AM »

Quote from: Codebyte
Please post and let me know the results

www.whatismyip.com agrees with your externalip.exe
Logged

Chris
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #20 on: June 30, 2008, 12:14:32 PM »

Good stuff! Thanks guys!
Logged

CodeByter.com - http://www.codebyter.com
wreckedcarzz
Charter Member
***
Posts: 1,620



Happy wolfie ^_^

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #21 on: July 01, 2008, 11:29:08 PM »

Thanks CodeByte! Works great smiley thumbs up
Logged

New website! With a fancy domain name and everything! *gasp*
http://www.wreckedcarzz.com/
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #22 on: July 02, 2008, 12:16:53 AM »

np, enjoy smiley let me know if you need something else
Logged

CodeByter.com - http://www.codebyter.com
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.136s | Server load: 0.05 ]