commit dea70eda0cc704296f9a67aa5024b7e4de5fba8f Author: Wizzard Date: Mon Feb 26 01:20:37 2024 -0500 First push diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..0d12046 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,18 @@ +pkgname=ip-lookup +pkgver=1.1 +pkgrel=1 +pkgdesc="A simple IP lookup tool that shows city, ASN, and other information. Deadzone.lol Motherfucker." +arch=('x86_64') +url="https://deadzone.lol" +license=('GPL') +depends=('curl' 'cjson') +source=("main.c") +sha256sums=('SKIP') + +build() { + gcc -o "$pkgname" "$srcdir/main.c" -lcurl -lcjson +} + +package() { + install -Dm755 "$srcdir/$pkgname" "$pkgdir/usr/bin/$pkgname" +} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..cc1f6ec --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +gcc -o ip-lookup main.c -lcurl -lcjson diff --git a/main.c b/main.c new file mode 100644 index 0000000..bc5b41a --- /dev/null +++ b/main.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include + +static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) { + size_t realsize = size * nmemb; + ((char *)userp)[realsize] = 0; + strcat(userp, contents); + return realsize; +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + printf("Usage: %s \n", argv[0]); + return 1; + } + + char url[256] = "http://ip-api.com/json/"; + strcat(url, argv[1]); + + CURL *curl; + CURLcode res; + char buffer[2048] = {0}; + + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); + + if (!curl) { + fprintf(stderr, "Error: Failed to initialize libcurl.\n"); + return 1; + } + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer); + + res = curl_easy_perform(curl); + + if (res != CURLE_OK) { + fprintf(stderr, "Error: Failed to fetch data from ip-api.com: %s\n", curl_easy_strerror(res)); + curl_easy_cleanup(curl); + return 1; + } + + curl_easy_cleanup(curl); + curl_global_cleanup(); + + cJSON *json = cJSON_Parse(buffer); + if (!json) { + fprintf(stderr, "Error: Failed to parse JSON data.\n"); + return 1; + } + + cJSON *status = cJSON_GetObjectItem(json, "status"); + if (status && cJSON_IsString(status) && strcmp(status->valuestring, "fail") == 0) { + fprintf(stderr, "Error: Failed to fetch data for IP address %s\n", argv[1]); + cJSON_Delete(json); + return 1; + } + + cJSON *city = cJSON_GetObjectItem(json, "city"); + cJSON *regionName = cJSON_GetObjectItem(json, "regionName"); + cJSON *country = cJSON_GetObjectItem(json, "country"); + cJSON *timezone = cJSON_GetObjectItem(json, "timezone"); + cJSON *zip = cJSON_GetObjectItem(json, "zip"); + cJSON *isp = cJSON_GetObjectItem(json, "isp"); + cJSON *org = cJSON_GetObjectItem(json, "org"); + cJSON *as = cJSON_GetObjectItem(json, "as"); + cJSON *hostname = cJSON_GetObjectItem(json, "hostName"); + + + printf("Hostname: %s\n", hostname ? hostname->valuestring : "Unknown"); + printf("City: %s\n", city ? city->valuestring : "Unknown"); + printf("Region: %s\n", regionName ? regionName->valuestring : "Unknown"); + printf("Country: %s\n", country ? country->valuestring : "Unknown"); + printf("Time Zone: %s\n", timezone ? timezone->valuestring : "Unknown"); + printf("ZIP: %s\n", zip ? zip->valuestring : "Unknown"); + printf("ISP: %s\n", isp ? isp->valuestring : "Unknown"); + printf("Organization: %s\n", org ? org->valuestring : "Unknown"); + printf("AS: %s\n", as ? as->valuestring : "Unknown"); + + cJSON_Delete(json); + return 0; +} diff --git a/src/main.c b/src/main.c new file mode 120000 index 0000000..cc2f2f3 --- /dev/null +++ b/src/main.c @@ -0,0 +1 @@ +/home/sweat/gitprojects/ip-lookup/main.c \ No newline at end of file