Compare commits

...

12 Commits

5 changed files with 155 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
pkgname=ip-lookup pkgname=ip-lookup
pkgver=1.2 pkgver=1.5.3
pkgrel=1 pkgrel=1
pkgdesc="A simple IP lookup tool that shows city, ASN, and other information. Deadzone.lol Motherfucker." pkgdesc="A simple IP lookup tool that shows city, ASN, and other information. Deadzone.lol Motherfucker."
arch=('x86_64') arch=('x86_64')

View File

@@ -1,13 +1,11 @@
## Installation # Arch install
# Arch
makepkg -si makepkg -si
# Fedora # Fedora install
run build-fedora.sh run build-fedora.sh
# Void # Void install
clone this repo into your `void-packages/srcpkgs` folder with the following command `git clone https://git.deadzone.lol/Wizzard/ip-lookup-void-template ip-lookup` (it must be named ip-lookup) clone this repo into your `void-packages/srcpkgs` folder with the following command `git clone https://git.deadzone.lol/Wizzard/ip-lookup` (it must be named ip-lookup)
## Usage ## Usage
ip-lookup (IP ADDRESS) ip-lookup (IP ADDRESS)

View File

@@ -1,5 +1,5 @@
Name: ip-lookup Name: ip-lookup
Version: 1.2 Version: 1.5.3
Release: 1%{?dist} Release: 1%{?dist}
Summary: A simple IP lookup tool Summary: A simple IP lookup tool
License: GPL License: GPL

View File

@@ -3,6 +3,118 @@
#include <string.h> #include <string.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <cjson/cJSON.h> #include <cjson/cJSON.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/stat.h>
#include <time.h>
#define VPN_DB_DIR "/tmp/vpndb"
#define VPN_LIST_PATH VPN_DB_DIR "/ipv4.txt"
#define VPN_LIST_URL "https://raw.githubusercontent.com/X4BNet/lists_vpn/main/ipv4.txt"
int ensure_directory_exists(const char *dirPath) {
struct stat st = {0};
if (stat(dirPath, &st) == -1) {
if (mkdir(dirPath, 0755) == -1) {
fprintf(stderr, "Failed to create directory %s\n", dirPath);
return -1;
}
}
return 0;
}
unsigned long ip_to_ulong(const char *ip) {
struct in_addr inVal;
if (inet_aton(ip, &inVal)) {
return ntohl(inVal.s_addr);
}
return 0;
}
int ip_in_cidr(const char *ip, const char *cidr) {
unsigned long ip_addr = ip_to_ulong(ip);
int mask;
char cidr_ip[INET_ADDRSTRLEN];
sscanf(cidr, "%[^/]/%d", cidr_ip, &mask);
unsigned long cidr_addr = ip_to_ulong(cidr_ip);
unsigned long cidr_mask = mask ? (~0 << (32 - mask)) : 0;
return (ip_addr & cidr_mask) == (cidr_addr & cidr_mask);
}
int is_vpn(const char *ip_address) {
FILE *file = fopen(VPN_LIST_PATH, "r");
if (!file) {
fprintf(stderr, "Cannot open VPN list file.\n");
return -1;
}
char line[INET_ADDRSTRLEN + 4];
while (fgets(line, sizeof(line), file)) {
line[strcspn(line, "\n")] = 0;
if (ip_in_cidr(ip_address, line)) {
fclose(file);
return 1;
}
}
fclose(file);
return 0;
}
static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
int download_vpn_list(const char *url, const char *output_path) {
struct stat fileInfo;
time_t now;
double hours;
time(&now);
if (stat(output_path, &fileInfo) == 0) {
hours = difftime(now, fileInfo.st_mtime) / (60.0 * 60.0);
if (hours < 24.0) {
return 0;
}
}
CURL *curl;
FILE *fp;
CURLcode res;
int result = 1; // Assume failure
curl = curl_easy_init();
if (curl) {
fp = fopen(output_path, "wb");
if (fp == NULL) {
fprintf(stderr, "Cannot open file %s\n", output_path);
curl_easy_cleanup(curl);
return result;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
if (res == CURLE_OK) {
result = 0; // Success
} else {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
fclose(fp);
curl_easy_cleanup(curl);
}
return result;
}
static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) { static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
@@ -17,6 +129,18 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
if (ensure_directory_exists(VPN_DB_DIR) != 0) {
fprintf(stderr, "Failed to create VPN database directory.\n");
return 1;
}
if (download_vpn_list(VPN_LIST_URL, VPN_LIST_PATH) != 0) {
fprintf(stderr, "Failed to download VPN list.\n");
return 1;
}
int vpnCheck = is_vpn(argv[1]);
char url[256] = "http://ip-api.com/json/"; char url[256] = "http://ip-api.com/json/";
strcat(url, argv[1]); strcat(url, argv[1]);
@@ -80,6 +204,7 @@ int main(int argc, char *argv[]) {
printf("ISP: %s\n", isp ? isp->valuestring : "Unknown"); printf("ISP: %s\n", isp ? isp->valuestring : "Unknown");
printf("Organization: %s\n", org ? org->valuestring : "Unknown"); printf("Organization: %s\n", org ? org->valuestring : "Unknown");
printf("AS: %s\n", as ? as->valuestring : "Unknown"); printf("AS: %s\n", as ? as->valuestring : "Unknown");
printf("VPN: %s\n", vpnCheck ? "True" : "False");
cJSON_Delete(json); cJSON_Delete(json);
return 0; return 0;

24
template Normal file
View File

@@ -0,0 +1,24 @@
pkgname=ip-lookup
version=1.5.3
revision=1
wrksrc="${pkgname}-${version}"
build_style=gnu-makefile
short_desc="An IP lookup tool"
maintainer="Rich <rich@bandaholics.cash>"
license="GPL-3.0-or-later"
homepage="https://git.deadzone.lol/Wizzard/ip-lookup"
hostmakedepends="git"
makedepends="libcurl-devel cJSON-devel"
do_fetch() {
git clone --depth 1 --branch "main" https://git.deadzone.lol/Wizzard/ip-lookup "${wrksrc}"
}
do_extract() {
:
}
do_build() {
make -C ${wrksrc} SRCDIR=${wrksrc}/src OBJDIR=${wrksrc}/bin
}
do_install() {
vbin ${wrksrc}/bin/ip-lookup
}