c++ - External IP Address -


possible duplicate:
stable way of retrieving external ip host behind nat

well, hello again. wondering how external ip address (external since people haves router) of computer?

here's 1 way of using user's suggestion ... of course works own ip determine opening command prompt , running ipconfig /all

#include <windows.h> #include <wininet.h> #include <iostream>  #pragma comment(lib, "wininet")  int main(int argc, char* argv[]) {     hinternet hinternet, hfile;     dword rsize;     char buffer[32];      hinternet = internetopen(null, internet_open_type_preconfig, null, null, 0);     hfile = internetopenurl(hinternet, "http://automation.whatismyip.com/n09230945.asp", null, 0, internet_flag_reload, 0);     internetreadfile(hfile, &buffer, sizeof(buffer), &rsize);     buffer[rsize] = '\0';      internetclosehandle(hfile);     internetclosehandle(hinternet);      std::cout << "your ip address: " << buffer << "\n";     system("pause");     return 0; }    

fyi: owner's of http://www.whatismyip.com/ request hit automation page once every 5 minutes feel compelled put caveat not run code more :p

note: http://automation.whatismyip.com/n09230945.asp newest address automation file. 5 minute / 300 second rule still in place.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -