Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,121 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,766 people online right now. Registration is fast and FREE... Join Now!




Getting the external IP

 
Reply to this topicStart new topic

Getting the external IP

bruce123
11 May, 2007 - 09:04 AM
Post #1

New D.I.C Head
*

Joined: 11 May, 2007
Posts: 5


My Contributions
Hi all. I'm trying to do this to get the external IP trough c++. But I'm not getting it to work. I'm trying to use it in a DLL which will get injected into an other process. And after i got the external ip i would like to check it with ip's stored in the dll. If read things about recieving it from sites that show your ip address. But unfortunatly im not getting it to work:(. So if someone can pls help me:D

So it would be smth like this:
CODE

#define ALLOWED_IPS = (11.11.11.11) || (11.11.11.12) etc etc

CHAR GetExternalIp(void)
{
                //Dunno? need you guys help here:D
}

CHAR Ip = GetExternalIp();
if(Ip =! ALLOWED_IPS)
{
        MessageBox(NULL, "Your IP is not in the list! Aborting...", "Error!", MB_ICONASTERISK + MB_OK);
}


This post has been edited by bruce123: 11 May, 2007 - 09:05 AM
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Getting The External IP
11 May, 2007 - 12:59 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
I am not really clear on what you are trying to do. For example if you are working on a server program then you can open a socket to listen to a given port and then when a connection attempt is made you can scan an IP list (I think you would need a loop rather than such an or statement) to see if the ip is allowed, if it isn't you can deny access.

But it sounds as though you are talking about scanning all IP's attempting to conncet to a computer on any port? This would be slightly more difficult.

What platform are you on (dll makes me think windows, but one never knows)? Are you talking about 1 socket or the while computer?
User is offlineProfile CardPM
+Quote Post

bruce123
RE: Getting The External IP
12 May, 2007 - 03:58 AM
Post #3

New D.I.C Head
*

Joined: 11 May, 2007
Posts: 5


My Contributions
No. I'm injecting a dll into a process, which is a game. And if the ip isn't in the list then it will make sure the person cant use the dll and so cant inject it into the game by letting an error message pop-up. And yes i'm using windows XP sp2. Thanks for your help!

This post has been edited by bruce123: 12 May, 2007 - 03:58 AM
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Getting The External IP
13 May, 2007 - 01:35 AM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Again you are not clear. Basicly it all comes down to what controls the access to the socket. If the dll has the code that makes the connection than it is rather easy. if the dll needs to moniter a socket created by another process this becomes a little more complicated.

If the connection is made by the game, then you will need to ask the operating system for the socket(s) that is(are) owned by the game's process. You can then ask the OS for the connected IP. Then run a loop to see if the IP is on your list.

If the connection is made by your dll then the external IP is easily found.
User is offlineProfile CardPM
+Quote Post

bruce123
RE: Getting The External IP
13 May, 2007 - 06:58 AM
Post #5

New D.I.C Head
*

Joined: 11 May, 2007
Posts: 5


My Contributions
The process only connects to the internet when you connect to the account server. Which happens a long time after the injection(an error message that long after wouldn't be to handy u see). So it would be better to let the dll do it by itself instead of using the game's. And the dll is doing nothing with sockets and I have no clue how to do this since i have never done it before.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Getting The External IP
13 May, 2007 - 11:15 PM
Post #6

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Well, I may not understand what you want to do... but it seems that you have a problem. It sounds as though you will have to ask the game what IP it wants to connect to. Until a connection is made there is no external IP to get. So only the Game knows what IP's it will attempt to connect to.

I have no idea how to ask the game what ip's it will want to connect to. Basicly it sounds like your problem is the basic idea of a filewall. If an attempt is made to connect to an IP that is not on the allowed list, you want to block that access. This can of course be done though most decent firewall programs so looking at how they work will help.

But what I want to get across to you is this: If your dll does not make the connection, then you will have to either get the information from whatever process DOES make the connection, OR you will have to wait until that process attempts to make a connection and intercept that attempt. There is no way to magicly "KNOW" what ip a process will try to connect to. -- At least not without resorting to "hacking" techniques which will not be stable or reliable.
User is offlineProfile CardPM
+Quote Post

bruce123
RE: Getting The External IP
14 May, 2007 - 05:56 AM
Post #7

New D.I.C Head
*

Joined: 11 May, 2007
Posts: 5


My Contributions
I want to get the ip that you like get when you go to: http://whatismyip.com
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:06PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month