1 Attachment(s)
How to get IP public, not a network IP using winsock??
Dear VBers..
I have a trouble when develop a system, a socket system.
the problem is, the IP that i want to use is the IP public which is come with server, but it's because the server use as a server gateway, so the IP which
is detected is the network (LAN) IP.
the attachment maybe could explain it.
the IP Address is LAN IP, not IP public server.
is there possible to solve them??
thanks a lot for your attention, and very sorry for my English.
Re: How to get IP public, not a network IP using winsock??
Hi.. Welcome to the forums...:wave:
Looks like you could get only the Local IP, if you are in a LAN network. Another option is to ping to an external site which will return the IP address of your computer.
Here's an example: http://www.planet-source-code.com/vb...56194&lngWId=1 :wave:
Re: How to get IP public, not a network IP using winsock??
Many small NAT routers support UPnP these days. If your server machine is behind one of these it is possible for programs to ask the router for the IP addresses of its external interfaces. Most small routers have just one external interface.
This requires that UPnP be turned on in the router, and that you have your computers' software firewall set up to allow UPnP traffic, and that your computer has UPnP Control Point API software installed.
The API comes with Windows (XP later) but it might not be installed. See How to enable the Universal Plug and Play (UPnP) in Windows XP so that you can connect to Games for Windows LIVE. To set up the Windows Firewall see How Windows Firewall affects the UPnP framework in Windows XP Service Pack 2. To turn UPnP on in your router see the router's documentation.
While this is a lot compared to scraping a Web site that returns the client IP that it sees, it should be more stable because your program will not be subject to URL changes and page layout changes.
It also gets you a lot more than just the external IP address. For example you can do port mapping from within your program instead of manually configuring it at the router. This can be more secure because when your program shuts down it can remove any port mappings that it uses, closing the hole.
All of that said, you still need to use the API in your programs. You might look at the PortMapper Class which wraps a few of these API calls in a way that works around a few VB6 issues with unsupported Variant types.
1 Attachment(s)
Re: How to get IP public, not a network IP using winsock??
@akhileshbc and @dilettante thx very much..
but it not yet solve my trouble.
maybe i have to explain how this software is work.
i have some device outdoor, where this device is to control and monitor some sensor.
this device is controlling and monitoring by the server.
this device use GPRS to communicate with the server, and off course its use IP and Port to communicate it.
my software (socket software) is the gateway between device and server. the main function is receive the monitoring data (mode listen) from device, and request some parameter from server to device (mode send).
so, if my socket just get the local IP, its impossible to communicate between server and device.
then the main trouble here is, how this socket knowing the IP which is listening is the IP server.
my friend say try redirecting IP, is it possible??
the sketch is just like in the attachment.
Re: How to get IP public, not a network IP using winsock??
Your "local IP addresses" are called private IP addresses because they are unknown to the Internet. Since private addresses are not routable they can exist in millions of networks because they only have meaning on the LANs behind NAT routers.
But this means devices on the Internet cannot address them.
A partial solution is to use a NAT router that supports NAPT (Network Address Port Translation), and most NAT routers do. This allows a port on the router's public interface to be mapped inward to another port on one of the private network's adapters (most machines have just one IP address).
A port mapping rule can be configured on the router to map all incoming connection requests for TCP port 12345 to TCP port 54321 at 192.168.100.100 for example.
Then if the machine at 192.168.100.100 has a service listening for incoming connections on TCP port 54321 machines on the Internet can request a connection to the router on TCP port 12345. The router will map such connection requests through to the machine running the service.
Remote systems connecting across the Internet need to know the router's public IP address and TCP port 12345 to connect. The router must have a fixed IP address to use normal DNS, or many routers will send updates to a dynamic DNS server if their public IP address changes. This way remote systems can use the router's fixed DNS name, and not need to know the actual IP address of the router on a fixed basis (since it might change via DHCP anyway).
For port mapping the "outside" and "inside" port numbers do not have to be different, and usually aren't, but they can be. Most NAT routers supporting NAPT will do mapping for both TCP and UDP.
Your server never actually has a public IP address in this scenario. Instead the router appears to be the server to devices on the Internet.
Re: How to get IP public, not a network IP using winsock??
Did you get this problem sorted out? Your project is very similar to an application I have written for monitoring vehicles and sensors. If you need details on how to overcome the IP problem then feel free to message me.