ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Programatically determining your IP Address...

(1/5) > >>

Codebyte:
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 :)

Eóin:
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/.

f0dder:
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.

Codebyte:
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?

f0dder:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version