1
var validIPAddress = function (queryIP) {
2
const iPv4 = () => {
3
const address = queryIP.split(".");
4
if (address.length !== 4) return null;
5

6
for (const str of address) {
7
const ip = parseInt(str);
8
if (ip < 0 || ip > 255) return null;
9
if (ip.toString() !== str) return null;
10
}
11
return "IPv4";
12
};
13

14
const iPv6 = () => {
15
const address = queryIP.split(":");
16
if (address.length !== 8) return null;
17
const config = "0123456789abcdefABCDEF";
18
const check = address.every((str) => {
19
if (str === "" || str.length > 4) return false;
20
for (const s of str) {
21
if (!config.includes(s)) return false;
22
}
23
return true;
24
});
25
return check ? "IPv6" : null;
26
};
27

28
return iPv4() ?? iPv6() ?? "Neither";
29
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0