mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 13:29:13 -04:00
feat(new tool): IP Geolocation
IP Geolocation information using ip-api.com FIx #454
This commit is contained in:
parent
7f5fa00147
commit
03f99d61d8
4 changed files with 135 additions and 1 deletions
1
components.d.ts
vendored
1
components.d.ts
vendored
|
@ -112,6 +112,7 @@ declare module '@vue/runtime-core' {
|
|||
IconMdiVideo: typeof import('~icons/mdi/video')['default']
|
||||
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
||||
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
||||
IpGeoLocation: typeof import('./src/tools/ip-geo-location/ip-geo-location.vue')['default']
|
||||
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
||||
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
|
||||
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
|
||||
|
|
|
@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
|
|||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as ipGeoLocation } from './ip-geo-location';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
|
@ -147,7 +148,15 @@ export const toolsByCategory: ToolCategory[] = [
|
|||
},
|
||||
{
|
||||
name: 'Network',
|
||||
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
|
||||
components: [
|
||||
ipv4SubnetCalculator,
|
||||
ipv4AddressConverter,
|
||||
ipv4RangeExpander,
|
||||
macAddressLookup,
|
||||
macAddressGenerator,
|
||||
ipv6UlaGenerator,
|
||||
ipGeoLocation,
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Math',
|
||||
|
|
12
src/tools/ip-geo-location/index.ts
Normal file
12
src/tools/ip-geo-location/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { World } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'IP Geo Location',
|
||||
path: '/ip-geo-location',
|
||||
description: 'Retrieve information about an IPv4/6 address or domain location',
|
||||
keywords: ['ip', 'domain', 'geo', 'location'],
|
||||
component: () => import('./ip-geo-location.vue'),
|
||||
icon: World,
|
||||
createdAt: new Date('2024-01-17'),
|
||||
});
|
112
src/tools/ip-geo-location/ip-geo-location.vue
Normal file
112
src/tools/ip-geo-location/ip-geo-location.vue
Normal file
|
@ -0,0 +1,112 @@
|
|||
<script setup lang="ts">
|
||||
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
|
||||
|
||||
const ipOrDomain = ref('8.8.8.8');
|
||||
const errorMessage = ref('');
|
||||
|
||||
const fields: Array<{ field: string; name: string }> = [
|
||||
{ field: 'message', name: 'Message' },
|
||||
{ field: 'continent', name: 'Continent Name' },
|
||||
{ field: 'continentCode', name: 'Continent code' },
|
||||
{ field: 'country', name: 'Country Name' },
|
||||
{ field: 'countryCode', name: 'Country Code' },
|
||||
{ field: 'region', name: 'Region/state Code' },
|
||||
{ field: 'regionName', name: 'Region/state Name' },
|
||||
{ field: 'city', name: 'City' },
|
||||
{ field: 'district', name: 'District' },
|
||||
{ field: 'zip', name: 'Zip Code' },
|
||||
{ field: 'lat', name: 'Latitude' },
|
||||
{ field: 'lon', name: 'Longitude' },
|
||||
{ field: 'timezone', name: 'Timezone' },
|
||||
{ field: 'offset', name: 'Timezone UTC DST offset (in seconds)' },
|
||||
{ field: 'currency', name: 'National Currency' },
|
||||
{ field: 'isp', name: 'ISP Name' },
|
||||
{ field: 'org', name: 'Organization Name' },
|
||||
{ field: 'as', name: 'AS Number and Organization' },
|
||||
{ field: 'asname', name: 'AS name (RIR)' },
|
||||
{ field: 'reverse', name: 'Reverse DNS of the IP' },
|
||||
{ field: 'mobile', name: 'Mobile (cellular) connection' },
|
||||
{ field: 'proxy', name: 'Proxy, VPN or Tor exit address' },
|
||||
{ field: 'hosting', name: 'Hosting, colocated or data center' },
|
||||
{ field: 'query', name: 'IP used for the query' },
|
||||
];
|
||||
|
||||
const geoInfos = ref<CKeyValueListItems>([]);
|
||||
const geoInfosData = ref<any>({});
|
||||
const status = ref<'pending' | 'error' | 'success'>('pending');
|
||||
|
||||
const openStreetMapUrl = computed(
|
||||
() => {
|
||||
const gpsLatitude = geoInfosData.value.lat;
|
||||
const gpsLongitude = geoInfosData.value.lon;
|
||||
return gpsLatitude && gpsLongitude ? `https://www.openstreetmap.org/?mlat=${gpsLatitude}&mlon=${gpsLongitude}#map=18/${gpsLatitude}/${gpsLongitude}` : undefined;
|
||||
},
|
||||
);
|
||||
|
||||
async function onGetInfos() {
|
||||
try {
|
||||
status.value = 'pending';
|
||||
|
||||
const geoInfoQueryResponse = await fetch(`http://ip-api.com/json/${ipOrDomain.value}`);
|
||||
if (!geoInfoQueryResponse.ok) {
|
||||
throw geoInfoQueryResponse.statusText;
|
||||
}
|
||||
|
||||
const data = await geoInfoQueryResponse.json();
|
||||
|
||||
const allGeoInfos = [];
|
||||
for (const field of fields) {
|
||||
if (data[field.field]) {
|
||||
allGeoInfos.push({
|
||||
label: field.name,
|
||||
value: data[field.field],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
status.value = 'success';
|
||||
geoInfos.value = allGeoInfos;
|
||||
geoInfosData.value = data;
|
||||
}
|
||||
catch (e: any) {
|
||||
errorMessage.value = e.toString();
|
||||
status.value = 'error';
|
||||
return [];
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div flex items-center gap-2>
|
||||
<c-input-text
|
||||
v-model:value="ipOrDomain"
|
||||
placeholder="Enter an IPv4/6 or a domain name"
|
||||
@update:value="() => { status = 'pending' }"
|
||||
/>
|
||||
<c-button align-center @click="onGetInfos">
|
||||
Get GEO Location Infos
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-card v-if="status === 'pending'" mt-5>
|
||||
Click on button above to get latest infos
|
||||
</c-card>
|
||||
|
||||
<c-card v-if="status === 'success' && openStreetMapUrl" mt-4>
|
||||
<c-button :href="openStreetMapUrl" target="_blank">
|
||||
Localize on Open Street Map
|
||||
</c-button>
|
||||
</c-card>
|
||||
|
||||
<c-card v-if="status === 'success'" mt-5>
|
||||
<c-key-value-list :items="geoInfos" />
|
||||
</c-card>
|
||||
|
||||
<n-alert v-if="status === 'error'" title="Errors occured" type="error" mt-5>
|
||||
{{ errorMessage }}
|
||||
</n-alert>
|
||||
</div>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue