|
Codebyte
|
 |
« 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 
|
|
|
|
« Last Edit: June 27, 2008, 11:47:42 AM by Codebyte »
|
Logged
|
|
|
|
|
Eóin
|
 |
« 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
|
 |
« Reply #2 on: June 27, 2008, 05:59:33 PM » |
|
What Eóin said  - 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
|
 |
« 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  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
|
|
|
|
|
f0dder
|
 |
« Reply #4 on: June 27, 2008, 07:06:06 PM » |
|
Don't go for line numbers - read up on regular expressions  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
|
 |
« 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
|
|
|
|
|
f0dder
|
 |
« 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
|
 |
« 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
|
|
|
|
|
Codebyte
|
 |
« 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
|
|
|
|
|
mouser
|
 |
« Reply #9 on: June 30, 2008, 12:09:24 AM » |
|
works well here. 
|
|
|
|
|
Logged
|
|
|
|
|
lanux128
|
 |
« 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!. 
|
|
|
|
|
Logged
|
|
|
|
|
wreckedcarzz
|
 |
« Reply #11 on: June 30, 2008, 02:11:52 AM » |
|
Works well here  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
|
|
|
|
|
cthorpe
|
 |
« 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
|
 |
« 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
|
|
|
|
|
wr975
|
 |
« 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.htmlJust 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
|
|
|
|
|
|
|
mediaguycouk
|
 |
« Reply #16 on: June 30, 2008, 09:36:52 AM » |
|
|
|
|
|
|
Logged
|
|
|
|
|
f0dder
|
 |
« Reply #17 on: June 30, 2008, 10:08:51 AM » |
|
|
|
|
|
|
Logged
|
 - carpe noctem
|
|
|
|
jgpaiva
|
 |
« 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   jk.. It's working here.
|
|
|
|
|
Logged
|
|
|
|
|
cranioscopical
|
 |
« Reply #19 on: June 30, 2008, 10:22:34 AM » |
|
Please post and let me know the results www.whatismyip.com agrees with your externalip.exe
|
|
|
|
|
Logged
|
Chris
|
|
|
|
Codebyte
|
 |
« Reply #20 on: June 30, 2008, 12:14:32 PM » |
|
Good stuff! Thanks guys!
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Codebyte
|
 |
« Reply #22 on: July 02, 2008, 12:16:53 AM » |
|
np, enjoy  let me know if you need something else
|
|
|
|
|
Logged
|
|
|
|
|