Skip to content

Full Toolkit for Next-Level Domain Analysis

Allow IP lookup through search form 🕵️‍♀️

Felix Wotschofsky894e97880703
diff --git a/app/_components/search-form.tsx b/app/_components/search-form.tsx
index 8d4813b..9b2e1ce 100644
--- a/app/_components/search-form.tsx
+++ b/app/_components/search-form.tsx
@@ -21,7 +21,15 @@ import { Input } from '@/components/ui/input';
import { ClientOnly } from '@/components/client-only';
import { EXAMPLE_DOMAINS } from '@/lib/data';
-import { cn, isAppleDevice, isValidDomain } from '@/lib/utils';
+import {
+ cn,
+ IPV4_REGEX,
+ IPV6_REGEX,
+ isAppleDevice,
+ isValidDomain,
+} from '@/lib/utils';
+
+import { IpDetailsModal } from '../lookup/[domain]/_components/ip-details-modal';
const normalizeDomain = (input: string) => {
let tDomain;
@@ -76,6 +84,7 @@ export const SearchForm: FC<SearchFormProps> = (props) => {
const [state, setState] = useState<FormStates>(FormStates.Initial);
const [isInvalid, setInvalid] = useState(false);
const [suggestionsVisible, setSuggestionsVisible] = useState(false);
+ const [ipDetailsOpen, setIpDetailsOpen] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
useHotkeys(
@@ -111,7 +120,17 @@ export const SearchForm: FC<SearchFormProps> = (props) => {
(event: FormEvent) => {
event.preventDefault();
- const normalizedDomain = normalizeDomain(domain);
+ const trimmedInput = domain.trim();
+ if (trimmedInput.length === 0) {
+ return;
+ }
+
+ if (trimmedInput.match(IPV4_REGEX) || trimmedInput.match(IPV6_REGEX)) {
+ setIpDetailsOpen(true);
+ return;
+ }
+
+ const normalizedDomain = normalizeDomain(trimmedInput);
if (!isValidDomain(normalizedDomain)) {
setInvalid(true);
return;
@@ -124,7 +143,7 @@ export const SearchForm: FC<SearchFormProps> = (props) => {
props: { domain: normalizedDomain },
});
},
- [setInvalid, domain, redirectUser, plausible]
+ [domain, setInvalid, setIpDetailsOpen, redirectUser, plausible]
);
const { suggestions } = useSuggestions(domain);
@@ -232,7 +251,7 @@ export const SearchForm: FC<SearchFormProps> = (props) => {
})}
type="text"
required
- placeholder="Search any domain or URL"
+ placeholder="Search any domain, URL or IP"
aria-label="Domain"
value={domain}
onInput={handleInput}
@@ -294,6 +313,12 @@ export const SearchForm: FC<SearchFormProps> = (props) => {
Lookup
</Button>
</form>
+
+ <IpDetailsModal
+ ip={domain.trim()}
+ open={ipDetailsOpen}
+ onOpenChange={setIpDetailsOpen}
+ />
</>
);
};
diff --git a/app/lookup/[domain]/(dns)/_components/record-row.tsx b/app/lookup/[domain]/(dns)/_components/record-row.tsx
index d2989a7..5605a3e 100644
--- a/app/lookup/[domain]/(dns)/_components/record-row.tsx
+++ b/app/lookup/[domain]/(dns)/_components/record-row.tsx
@@ -4,17 +4,12 @@ import reactStringReplace from 'react-string-replace';
import { TableCell, TableRow } from '@/components/ui/table';
import type { RecordContextEntry } from '@/lib/record-context';
-import { cn } from '@/lib/utils';
+import { cn, DOMAIN_REGEX, IPV4_REGEX, IPV6_REGEX } from '@/lib/utils';
import { DomainLink } from '../../_components/domain-link';
import { IpLink } from '../../_components/ip-link';
import { RecordSubvalues } from './record-subvalues';
-const DOMAIN_REGEX = /([a-zA-Z0-9-_]+\.)+[a-z]+\.?/gi;
-const IPV4_REGEX = /(\d{1,3}\.){3}\d{1,3}/g;
-const IPV6_REGEX =
- /((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?/gi;
-
type RecordRowProps = {
name: string;
TTL: number;
diff --git a/lib/utils.ts b/lib/utils.ts
index ba7eeb1..f71e9f8 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -2,6 +2,11 @@ import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { getDomain, parse as tldtsParse } from 'tldts';
+export const DOMAIN_REGEX = /([a-zA-Z0-9-_]+\.)+[a-z]+\.?/gi;
+export const IPV4_REGEX = /(\d{1,3}\.){3}\d{1,3}/g;
+export const IPV6_REGEX =
+ /((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?/gi;
+
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));
export const deduplicate = <T>(array: T[]): T[] => Array.from(new Set(array));