Official JavaScript/TypeScript client for myip.foo - a free, privacy-focused IP lookup API.
- Full TypeScript support
- Works in Node.js and browsers
- React hooks included
- Dual-stack IPv4/IPv6 support
- No API key required
- Zero dependencies (React is optional)
npm install myip-fooimport { getIP, getIPData, getDualStack } from 'myip-foo';
// Get plain IP
const ip = await getIP();
console.log(ip); // "203.0.113.42"
// Get full data with geolocation
const data = await getIPData();
console.log(data.ip); // "203.0.113.42"
console.log(data.location.city); // "Amsterdam"
console.log(data.location.country); // "NL"
console.log(data.network.isp); // "KPN B.V."
console.log(data.connectionType); // "residential"
// Get both IPv4 and IPv6
const dualStack = await getDualStack();
console.log(dualStack.ipv4); // "203.0.113.42"
console.log(dualStack.ipv6); // "2001:db8::1" or nullimport { useIPData, useDualStack, useIP } from 'myip-foo';
function MyComponent() {
const { data, loading, error, refetch } = useIPData();
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;
return (
<div>
<p>IP: {data?.ip}</p>
<p>Location: {data?.location.city}, {data?.location.country}</p>
<p>ISP: {data?.network.isp}</p>
<button onClick={refetch}>Refresh</button>
</div>
);
}Returns your IP address as plain text.
Returns full IP data including geolocation.
Returns both IPv4 and IPv6 addresses (uses dedicated endpoints).
Detects if connection is residential, VPN, or datacenter.
Returns all HTTP headers as seen by the server.
Returns your user agent string.
Hook for fetching full IP data.
const { data, loading, error, refetch } = useIPData();Hook for fetching IPv4 and IPv6.
const { data, loading, error, refetch } = useDualStack();
// data.ipv4, data.ipv6Hook for fetching plain IP.
const { ip, loading, error, refetch } = useIP();interface IPData {
ip: string;
type: 'IPv4' | 'IPv6';
hostname?: string;
connectionType?: 'residential' | 'vpn' | 'datacenter' | 'tor';
location: {
country: string;
city: string;
region: string;
postalCode: string;
timezone: string;
latitude: string;
longitude: string;
};
network: {
asn: number;
isp: string;
};
cloudflare: {
colo: string;
ray: string;
};
}
interface DualStackData {
ipv4: string | null;
ipv6: string | null;
}
interface ConnectionTypeData {
ip: string;
type: 'residential' | 'vpn' | 'datacenter' | 'unknown';
}The getDualStack() function uses dedicated subdomains with direct DNS records:
ipv4.myip.foo/ip- Returns IPv4 only (A record)ipv6.myip.foo/ip- Returns IPv6 only (AAAA record)
This bypasses Cloudflare's dual-stack routing for accurate results.
myip.foo does not log IP addresses or use cookies. See Privacy Policy.
- Website: myip.foo
- API Docs: myip.foo/api-docs
- GitHub: myip-packages
MIT License - see LICENSE for details.