Hello everyone,
I just started learning c++ and I started with creating a programme that gets your wan ip adress.
Just because it covers some basic stuff.
Getting the content of the website works fine. But the parsing doesn't really work. If tried with sscanf, but it didn't work. Also using regex from the boost libraries didn't work. I think it's because that it uses stings and my output is a char.
So if anyone could give me a good and compact way to extract the ip out of the content, it would be very nice.
You can also give me other advice to improve my skills. :)
#include <windows.h>
#include <wininet.h>
#include <iostream>
#pragma comment (lib, "wininet.lib")
using namespace std;
HINTERNET hOpen, hFile;
char buffer[200];
DWORD ret;
int main() {
hOpen = InternetOpen("Mozilla/5.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hOpen) {
cout << "error: no connection" << endl;
return 0;
}
hFile = InternetOpenUrl(hOpen, "http://checkip.dyndns.org", NULL, 0, 0, 0);
if (!hFile) {
cout << "error: 'check website' offline" << endl;
return 0;
}
InternetReadFile(hFile, buffer, sizeof(buffer), &ret);
cout << buffer;
return 0;
}
Thx in advance