Sign in to follow this  
Renegadeandy

WAN IP in C++

Recommended Posts

Hi! I am desperate to find the correct code to find the WAN IP using C++ for one of my applications. I know how to find local IP, but thats not what I need. Does anybody have any code segments which will help me here? Thanks Andy

Share this post


Link to post
Share on other sites
Why do you *need* to know it?

You shouldn't need to know that and it likely won't do you any good anyway. If someone tries to connect to your WAN IP address they'll just get bounced by whichever machine is providing your local IP address. All machines behind the DNS server have exactly the same WAN address.

The typical solution is to have clients connect to a known server address and the server then keeps those connections open and routes all communication through them. Basically, client is responsible for opening sockets so that the server can talk to them

-me

Share this post


Link to post
Share on other sites
I need it for a support bit of software - i must have there WAN IP , however thats not the point you dont need to know *WHY* , just somebody please tell me *HOW*!

Share this post


Link to post
Share on other sites
The only way you can know your global IP is if you contact an outside source (like whatismyip.com). Hosts know nothing about whether or not NAT is enabled.

Share this post


Link to post
Share on other sites
Right, ok - so any hints on how the hell I am going to do that :S!

Or - the other option is , programming somehow to create a remote assistance invitation - which i could then deal with which would cut out that problem.

How would I go about programming that!

Share this post


Link to post
Share on other sites
If you're behind a server that supports UPnP (most home routers do, if that's what you're targeting), IIRC there's a way to query it for a WAN IP, but it's been a few years and I don't remember all the details. If you're on Windows ME or later you can use the UPnP APIs. They're COM-based so you can use them from C++ pretty easily. The ControlPoint API is the one that provides you an interface to a UPnP server.

Alternatively, Platinum UPnP is an open-source, cross-platform API that's used in a lot of applications.

Share this post


Link to post
Share on other sites
I am not that great a programmer, and very early in programming in C++ so I need more of a walkthrough than that.

Can you guide me through this? I know thats a big ask but it would be superb and hey - you would remind yourself all over again of what you need to do!

Thanks in advance,

Andy

Share this post


Link to post
Share on other sites
So, you're trying to write a trojan, that will send out Remote Assistance invites to your computer, so that you can log into them?

And you need the WAN IP so that you know where to connect?

Share this post


Link to post
Share on other sites
No, - please dont spam and ruin this thread. Its for a remote assistance business = upsetpc.com my site.

I could use real vnc or something - but then the client would need to do something and you cannot assume they would a) want to , or b)know how to.

So stop the stupid replys and more of the useful one like 2 posts back!

Share this post


Link to post
Share on other sites
Before starting with coding, realize the following limitations.

- Firewalls will block you. So trying to connect to a machine behind a firewall will require the user to reconfigure their router or software firewall. This is something that is strongly frowned upon.

- No computer will ever allow you to be contacted by 3rd party unless the user specifically set it up (Remote Assistance for example). Any software that would allow third party connection to take control over the computer is a security disaster of cosmic proportions

- If the computer you're trying to assist connects to your server, you have their WAN IP

- No matter which method you wish to use to assist your customers, they'll need to install the software. In addition, they'll need to start it and accept the connection whenever they require assistance. Once again, for security reasons

- Requiring unattended access to computers either via third party software or your own will quickly get you and your software black-listed

- It always helps to be polite and helpful when asking for assistance from volunteers

Share this post


Link to post
Share on other sites
Quote:
Original post by Renegadeandy
So stop the stupid replys and more of the useful one like 2 posts back!


Aside from your own posts, I've only seen 1 at-all-"stupid" reply. And even that was a sardonic reply to this bit of biting-the-hand-that-feeds:

Quote:
Original post by Renegadeandy
I need it for a support bit of software - i must have there WAN IP , however thats not the point you dont need to know *WHY* , just somebody please tell me *HOW*!


You've presupposed that getting the WAN IP of your host is the only possible solution to the problem you're trying to solve. A smart programmer realizes there are often many solutions of varying quality, and by exposing the *WHY*, he won't write off any -- quite possibly better -- alternatives.

Given that a WAN IP alone is worthless (for reasons Antheus was then kind enough to list, even after your snapping at him), it follows that you almost certainly wanted either an alternative you've not considered, or something more than just the WAN IP address. Answering *WHY* fills us in enough to be able to help with *EITHER*.

Since Antheus seems to have managed to goad the answer out of you for this thread, this is mainly just meant as advice for future posts -- pointing out why answering *WHY?* is usually a good idea. It'll also prevent some "stupid" replies from happening in the first place. Win-win situation!

Share this post


Link to post
Share on other sites
Ok.

Points taken on board thanks for the advice.

Perhaps as i suggested above an easier way to do this is to create a bit of code which will generate a remote assistance ticket - building upon the software already in place by microsoft. If this can be done - I can then send that to a server via ftp for example - And i can then download and deal with the ticket.

Seem ok?

Share this post


Link to post
Share on other sites
I did this just yesterday.

I used TightVNC.

I put a button in the clients program which runs the vnc server and tells it to connect to my PC (cause I know my internet IP, which is dynamic so I use DynDNS.com). It does this through the connect switch -connect <your ip here>

On my PC I have the VNC viewer in listen mode.

So when they press the button, their server runs, connects to my listener and I'm connected to their PC.

PS I'm pretty sure it goes through firewalls and I dont think there is a way to generate a Remote Assistance invitation. Well I couldnt find out how anyway.

Share this post


Link to post
Share on other sites
But didnt you need vnc to be installed on their pc first , by them!

I am trying to avoid them having to do that and set that up.

Can you go into more detail if the answer is No to above, cos this sounds perfect!

Share this post


Link to post
Share on other sites
Well you dont need to if you're only trying to connect to them with VNC.

They actually connect to you. So all you need is your IP. If your IP is dynamic then you can use a service like www.dyndns.com which gives you a static address pointing to your IP. I set my router to auto update dyndns as well so it should always point to my IP.

Share this post


Link to post
Share on other sites
But if they are server, how the hell do they connect to u - surely thats the wrong way round - cos ur then running the VNC client, the client connects to the server doesnt it?

Share this post


Link to post
Share on other sites
Yes I know its confusing. I didnt know it could do it either but I found out it can.

You see you put the VNC Viewer in listening mode on your PC. So the Viewer is listening for a server to connect to. Then when the person you're trying to help runs their server with the command -connect <your ip here> (or they click the button you make that does this automatically ;) it tells the server to connect to your viewer.

So yeah the VNC Server they run can connect to your VNC Viewer.

Share this post


Link to post
Share on other sites
And act as if i am connecting to them instead?! Very very clever!

Exactly what i need.

Now can you explain the code for this button - connect <ip> as im not sure if there is some sort of vnc api or something i should be looking at!

The code or some of it for the button would make my day!

Thanks so much - you have been fantastic with this!

Share this post


Link to post
Share on other sites
All you need to do is run the exe with the switch. So you could use ShellExecute()

So say for instance the server was at C:\MyProgram\WinVNC.exe

You would do something like

ShellExecute(NULL, "open", "C:\\MyProgram\\WinVNC.exe -connect your.ip.address", NULL,NULL,SW_MINIMIZE);

You'll need to make sure windows.h is included.

For more info on ShellExecute look at the MSDN docs http://msdn2.microsoft.com/en-us/library/ms647732.aspx

I think thats basically it

Share this post


Link to post
Share on other sites
Also,

ShellExecute(NULL, "open", "winvnc4.exe", NULL,NULL,SW_MINIMIZE);

works fine -
but

ShellExecute(NULL, "open", "winvnc4.exe -connect 192.168.62.51", NULL,NULL,SW_MINIMIZE);

doesnt even open the server - probably because it doesnt do the connecting and doesnt understand the command....this is what i thought would happen. What am i doing wrong!

Share this post


Link to post
Share on other sites
Maybe because "winvnc4.exe -connect 192.168.62.51" is not the name of an executable... Try instead :


ShellExecute(NULL, "open", "winvnc4.exe", "-connect 192.168.62.51", NULL,SW_MINIMIZE);

?


Looking at the prototype / manual (google) before using a function is a *good* habbit, don't you think ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this