-
Notifications
You must be signed in to change notification settings - Fork 3
/
ip.c
37 lines (31 loc) · 937 Bytes
/
ip.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Copyright (C) 2010 IsmAvatar <[email protected]>
This file is part of EnigmaNet
EnigmaNet is free software and comes with ABSOLUTELY NO WARRANTY.
See LICENSE for details.
*/
/*
gcc ip.c -o ip.exe -Iinclude -Llib -DCURL_STATICLIB -lcurl -lssh2 C:/MinGW/bin/libeay32.dll C:/MinGW/bin/libssl32.dll -lwldap32 -lws2_32 -lz
*/
#include <curl/curl.h>
#define IPLEN 24
char ip[IPLEN];
int p = 0;
int handle_data(void *ptr, int size, int nmemb, void *stream) {
int i, numbytes = size * nmemb;
char *str = (char *)ptr;
for (i = 0; i < numbytes && p < IPLEN - 1; i++)
ip[p++] = str[i];
ip[p] = '\0';
}
int main() {
char *site = "http://www.whatismyip.com/automation/n09230945.asp";
CURL *curl = curl_easy_init();
if (!curl) { return 0; }
curl_easy_setopt(curl, CURLOPT_URL, site);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handle_data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
printf("%s\n",ip);
return 0;
}