How can I programmatically get the Internet IP address?
1) If the computer is directly connected to the Internet using a USB modem.
2) If the computer is connected to the internet via another computer or a modem/router.
I there a way to do both?
P.S. This link gives exactly the Internet IP, but how can I use it in my program?
You can write socket code to send an http request to that link.
Under unix/linux/cygwin you can use system(“wget http://www.whatismyip.com/automation/n09230945.asp“); then open the file “n09230945.asp” and read its contents.
Here is an example of how to make the request using sockets (I modified an online example for this specific purpose). NOTE: It is an example and a real implementation would need to handle the errors better: