Skip to content

Instantly share code, notes, and snippets.

@optionsx
Last active February 27, 2023 04:56
Show Gist options
  • Save optionsx/fd3f4b4a1453f461ba82a6a5278a83f5 to your computer and use it in GitHub Desktop.
Save optionsx/fd3f4b4a1453f461ba82a6a5278a83f5 to your computer and use it in GitHub Desktop.
was about to delete cus the api needed proxy, rather leave it in this dumpster for record.
import axiod from "https://deno.land/x/axiod@0.26.2/mod.ts";
const subdomains = ["ping", "eu", "us", "au", "whitelabel", "rotate", "fn2"];
const proxies = new Map<string, ProxyData>();
interface ProxyData {
success: boolean;
isProxy: boolean;
country: string;
region: string;
city: string;
hostname: string;
isp: string;
error?: string;
}
export const isProxy = async (
ip: string,
): Promise<ProxyData | { error: string }> => {
try {
if (proxies.has(ip)) return proxies.get(ip) as ProxyData;
const subdomain = subdomains[Math.floor(Math.random() * subdomains.length)];
console.log(subdomain);
const source = await axiod(
`https://${subdomain}.ipqualityscore.com/free-ip-lookup-proxy-vpn-test/lookup/${ip}`,
{
headers: {
accept: "s",
"accept-language": "en-GB,en;q=0.9,en-US;q=0.8",
},
responseType: "text",
timeout: 50000,
},
);
const [, data] = source.data.match(/>(.*)<\/h2>/) as string;
const [isp_city, region, country] = data
.split(",")
.map((x: string) => x.trim());
const [isp, city] = isp_city.split(" - ");
const [, hostname] = source.data.match(
/<td>Hostname<\/td>\s+<td>(.*)<\/td>/,
) as string;
const isProxy = !source.data.includes("Not A Proxy/VPN");
proxies.set(ip, {
success: true,
isProxy,
country,
region,
city,
hostname,
isp,
});
if (isp.startsWith("Reserved") || !isp) return { success: false, error: "Invalid IP" };
return {
success: true,
isProxy,
country,
region,
city,
hostname,
isp,
};
} catch (err) {
console.log(err);
return { success: false, error: err.message };
}
};
export const isValidIP = (input: string): boolean =>
/^([0-9]{1,3}\.){3}[0-9]{1,3}$/.test(input) ||
/^([a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i.test(input);
export default isProxy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment