diff --git a/src/components/DevAreaTools/IPLookup.jsx b/src/components/DevAreaTools/IPLookup.jsx index 86efa84..a3d3228 100644 --- a/src/components/DevAreaTools/IPLookup.jsx +++ b/src/components/DevAreaTools/IPLookup.jsx @@ -4,22 +4,28 @@ export default function IPLookup() { const [ipAddress, setIpAddress] = useState(''); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); const lookupIP = async (ip) => { setLoading(true); + setError(null); try { - // Using ipapi.co - free, no API key - const url = ip - ? `https://ipapi.co/${ip}/json/` - : 'https://ipapi.co/json/'; - + const url = ip + ? `http://ip-api.com/json/${ip}?fields=status,message,country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,query` + : `http://ip-api.com/json/?fields=status,message,country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,query`; + const response = await fetch(url); const data = await response.json(); - - setResult(data); - } catch (error) { - console.error('Error:', error); - setResult({ error: 'Failed to lookup IP' }); + + if (data.status === 'fail') { + setError(data.message); + setResult(null); + } else { + setResult(data); + } + } catch (err) { + setError('Failed to lookup IP'); + console.error('Error:', err); } setLoading(false); }; @@ -30,50 +36,87 @@ export default function IPLookup() { }; return ( -
-

IP Address Lookup

- -
+
+

IP Address Lookup

+ +
setIpAddress(e.target.value)} - className="flex-1 px-4 py-2 border rounded" + className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" /> - -
- {loading &&

Loading...

} - - {result && !result.error && ( -
-

IP: {result.ip}

-

City: {result.city}

-

Region: {result.region}

-

Country: {result.country_name}

-

Timezone: {result.timezone}

-

ISP: {result.org}

-

Latitude: {result.latitude}

-

Longitude: {result.longitude}

+ {error && ( +
+ {error}
)} - {result?.error && ( -

{result.error}

+ {result && ( +
+
+

IP Information

+
+
+
+ IP Address + {result.query} +
+
+ Country + {result.country} ({result.countryCode}) +
+
+ Region + {result.regionName} +
+
+ City + {result.city} +
+
+ ZIP Code + {result.zip || 'N/A'} +
+
+ Timezone + {result.timezone} +
+
+ ISP + {result.isp} +
+
+ Organization + {result.org} +
+
+ AS Number + {result.as} +
+
+ Coordinates + {result.lat}, {result.lon} +
+
+
)}
);