Open ip-lookup in Script Kit

// Name: IP & Domain Lookup
// Description: Get information about an IP address or domain
// Author: Vedinsoh
// GitHub: @Vedinsoh
import "@johnlindquist/kit";
import net from "node:net";
import { URL } from "node:url";
const getLookupData = async (query) => {
// Reference: https://ip-api.com/docs/api:json
const response = await get(
`http://ip-api.com/json/${query}?fields=status,message,continent,country,countryCode,regionName,city,zip,lat,lon,timezone,isp,org,as,query`
);
if (response.data.status === "fail") {
throw new Error(response.data.message);
}
return response.data;
};
let lookupQuery = await arg({
placeholder: "Enter IP address or domain",
validate: (value) => {
if (net.isIP(value) !== 0) {
return true;
} else {
try {
new URL(`https://${value}`);
return true;
} catch (e) {
return "Please enter a valid IP address or domain";
}
}
},
});
const data = await getLookupData(lookupQuery);
div(
md(`
# IP Lookup: ${lookupQuery}
- **IP:** ${data.query}
- **ISP:** ${data.isp}
- **Organization:** ${data.org}
- **AS:** ${data.as}
- **Continent:** ${data.continent}
- **Country:** ${data.country} (${data.countryCode})
- **Region:** ${data.regionName}
- **City:** ${data.city}
- **Zip Code:** ${data.zip}
- **Latitude:** ${data.lat}
- **Longitude:** ${data.lon}
- **Timezone:** ${data.timezone}
`)
);