mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-25 23:24:14 +03:00
Format
This commit is contained in:
1 parent
ad0172b3c8
commit
e1fafbe1e4
11 files changed
+36
-51
No files matched your search
@@ -47,7 +47,7 @@ function isValidIPv6(ip: string): boolean {
|
||||
if (parts.length === 1) {
|
||||
// No compression
|
||||
groups = cleanIP.split(':');
|
||||
|
||||
|
||||
// Check for IPv4-mapped addresses
|
||||
const lastGroup = groups[groups.length - 1];
|
||||
let ipv4Groups = 0;
|
||||
@@ -64,7 +64,7 @@ function isValidIPv6(ip: string): boolean {
|
||||
groups.pop(); // Remove IPv4 part from groups for validation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Should have 8 groups total (or 6 + IPv4 which counts as 2)
|
||||
const expectedGroups = ipv4Groups > 0 ? 6 : 8;
|
||||
if (groups.length !== expectedGroups) return false;
|
||||
@@ -130,7 +130,7 @@ function expandIPv6(ip: string): string {
|
||||
// Already expanded, just pad with zeros
|
||||
const groups = cleanIP.split(':');
|
||||
const expandedGroups: string[] = [];
|
||||
|
||||
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
const group = groups[i];
|
||||
if (group.includes('.')) {
|
||||
|
||||
@@ -78,7 +78,7 @@ function expandIPv6(ip: string): string {
|
||||
function compressIPv6(ip: string): string {
|
||||
// Simple IPv6 compression - find longest sequence of consecutive zeros
|
||||
const groups = ip.split(':');
|
||||
|
||||
|
||||
// Find longest sequence of '0' groups
|
||||
let longestStart = -1;
|
||||
let longestLength = 0;
|
||||
@@ -138,7 +138,7 @@ function bigIntToIPv6(num: bigint): string {
|
||||
}
|
||||
|
||||
const uncompressed = groups.join(':');
|
||||
|
||||
|
||||
// Apply IPv6 compression using our normalize function
|
||||
try {
|
||||
const result = normalizeIPv6Addresses([uncompressed]);
|
||||
@@ -148,7 +148,7 @@ function bigIntToIPv6(num: bigint): string {
|
||||
} catch {
|
||||
// Fallback to manual compression if normalize fails
|
||||
}
|
||||
|
||||
|
||||
// Manual compression fallback
|
||||
return compressIPv6(uncompressed);
|
||||
}
|
||||
|
||||
@@ -367,12 +367,12 @@ function parseInputLine(line: string): {
|
||||
if (match) {
|
||||
const countStr = match[2].trim();
|
||||
const count = parseInt(countStr, 10);
|
||||
|
||||
|
||||
// Check if the count is a valid number
|
||||
if (isNaN(count) || count < 0) {
|
||||
throw new Error(`Invalid count format: "${countStr}"`);
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
network: match[1].trim(),
|
||||
count: count,
|
||||
|
||||
@@ -36,7 +36,7 @@ function isValidIPv4(ip: string): boolean {
|
||||
function isValidIPv6(ip: string): boolean {
|
||||
// Check for triple colons (invalid)
|
||||
if (ip.includes(':::')) return false;
|
||||
|
||||
|
||||
// Handle zone identifiers (e.g., fe80::1%eth0)
|
||||
let cleanIP = ip;
|
||||
if (ip.includes('%')) {
|
||||
@@ -46,7 +46,7 @@ function isValidIPv6(ip: string): boolean {
|
||||
// Zone identifier part should not be empty
|
||||
if (!parts[1]) return false;
|
||||
}
|
||||
|
||||
|
||||
// Basic IPv6 validation - handles compressed notation
|
||||
if (cleanIP.includes('::')) {
|
||||
const parts = cleanIP.split('::');
|
||||
|
||||
+12
-11
@@ -90,7 +90,7 @@ function generateULA(subnetId?: string): ULAGeneration {
|
||||
const hash = generateHash(hashInput);
|
||||
// Global ID is 40 bits = 10 hex chars for RFC compliance
|
||||
const fullGlobalIDHex = hash.substring(hash.length - 10); // Last 10 hex chars (40 bits)
|
||||
|
||||
|
||||
// For ULA format, we use 8 hex chars in the address format
|
||||
const globalIDHex = fullGlobalIDHex.substring(2); // Take 8 chars for address format
|
||||
|
||||
@@ -268,7 +268,7 @@ export function parseULA(ula: string): {
|
||||
|
||||
// Split into groups
|
||||
const groups = addressPart.split(':');
|
||||
|
||||
|
||||
if (groups.length < 3) {
|
||||
return {
|
||||
isValid: false,
|
||||
@@ -281,20 +281,21 @@ export function parseULA(ula: string): {
|
||||
// Detect format type based on first group length
|
||||
if (firstGroup.length > 8) {
|
||||
// Compressed format: fd12345678:abcd::1 (our generated format)
|
||||
if (firstGroup.length < 10) { // fd + 8 hex chars
|
||||
if (firstGroup.length < 10) {
|
||||
// fd + 8 hex chars
|
||||
return {
|
||||
isValid: false,
|
||||
error: 'Invalid ULA format - first group too short for compressed format',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Extract global ID from first group (remove fd prefix)
|
||||
const globalIDHex = firstGroup.substring(2); // Remove 'fd'
|
||||
const globalID = globalIDHex.match(/.{4}/g)?.join(':') || '';
|
||||
|
||||
|
||||
// Subnet ID is the second group
|
||||
const subnetID = groups[1];
|
||||
|
||||
|
||||
// Interface ID is remaining groups
|
||||
let interfaceID = '';
|
||||
if (groups.length > 2) {
|
||||
@@ -311,7 +312,7 @@ export function parseULA(ula: string): {
|
||||
};
|
||||
} else {
|
||||
// Standard IPv6 format: fd12:3456:789a:bcde:... or compressed fd12:3456:789a::1
|
||||
|
||||
|
||||
// Handle compressed notation by expanding first
|
||||
let expandedULA = cleanULA;
|
||||
if (cleanULA.includes('::')) {
|
||||
@@ -327,7 +328,7 @@ export function parseULA(ula: string): {
|
||||
const leftGroups = parts[0] ? parts[0].split(':') : [];
|
||||
const rightGroups = parts[1] ? parts[1].split(':') : [];
|
||||
const missingGroups = 8 - leftGroups.length - rightGroups.length;
|
||||
|
||||
|
||||
if (missingGroups < 0) {
|
||||
return {
|
||||
isValid: false,
|
||||
@@ -342,7 +343,7 @@ export function parseULA(ula: string): {
|
||||
|
||||
// Split expanded ULA into groups
|
||||
const expandedGroups = expandedULA.split(':');
|
||||
|
||||
|
||||
if (expandedGroups.length !== 8) {
|
||||
return {
|
||||
isValid: false,
|
||||
@@ -351,7 +352,7 @@ export function parseULA(ula: string): {
|
||||
}
|
||||
|
||||
// Pad groups to 4 characters for consistent processing
|
||||
const paddedGroups = expandedGroups.map(group => group.padStart(4, '0'));
|
||||
const paddedGroups = expandedGroups.map((group) => group.padStart(4, '0'));
|
||||
|
||||
const globalIDPart1 = paddedGroups[0].substring(2); // '00' from 'fd00'
|
||||
const globalIDPart2 = paddedGroups[1]; // '1234'
|
||||
@@ -367,7 +368,7 @@ export function parseULA(ula: string): {
|
||||
const fourthGroupRemainder = paddedGroups[3].substring(2); // 'bc' from '9abc'
|
||||
const remainingGroups = paddedGroups.slice(4); // everything after 4th group
|
||||
const interfaceHexString = fourthGroupRemainder + remainingGroups.join('');
|
||||
|
||||
|
||||
// Handle special cases for interface ID
|
||||
let interfaceID: string;
|
||||
if (cleanULA.includes('::')) {
|
||||
|
||||
@@ -73,8 +73,7 @@ function isValidSubnetMask(mask: string): boolean {
|
||||
|
||||
// Valid subnet mask has contiguous 1s followed by contiguous 0s
|
||||
// Special cases: 0.0.0.0 (all zeros) and 255.255.255.255 (all ones) are valid
|
||||
if (maskBinary === '00000000000000000000000000000000' ||
|
||||
maskBinary === '11111111111111111111111111111111') {
|
||||
if (maskBinary === '00000000000000000000000000000000' || maskBinary === '11111111111111111111111111111111') {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -113,8 +112,7 @@ function isValidWildcardMask(mask: string): boolean {
|
||||
|
||||
// Valid wildcard mask has contiguous 0s followed by contiguous 1s
|
||||
// Special cases: 0.0.0.0 (all zeros) and 255.255.255.255 (all ones) are valid
|
||||
if (maskBinary === '00000000000000000000000000000000' ||
|
||||
maskBinary === '11111111111111111111111111111111') {
|
||||
if (maskBinary === '00000000000000000000000000000000' || maskBinary === '11111111111111111111111111111111') {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,14 +154,14 @@ function isValidIPv6(ip: string): boolean {
|
||||
|
||||
// Validate all groups
|
||||
const allGroups = [...left, ...right];
|
||||
return allGroups.every(group => /^[0-9a-fA-F]{0,4}$/.test(group));
|
||||
return allGroups.every((group) => /^[0-9a-fA-F]{0,4}$/.test(group));
|
||||
} else {
|
||||
// No compression - must have exactly 8 groups
|
||||
const groups = ip.split(':');
|
||||
if (groups.length !== 8) return false;
|
||||
|
||||
// All groups must be valid hex (1-4 characters)
|
||||
return groups.every(group => /^[0-9a-fA-F]{1,4}$/.test(group));
|
||||
return groups.every((group) => /^[0-9a-fA-F]{1,4}$/.test(group));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,6 @@ export function parseZoneFile(content: string): ParsedZone {
|
||||
}
|
||||
|
||||
for (const { line, lineNum, startsWithWhitespace } of processedLines) {
|
||||
|
||||
try {
|
||||
// Handle $ORIGIN directive
|
||||
if (line.startsWith('$ORIGIN')) {
|
||||
|
||||
@@ -373,11 +373,7 @@ function createReverseZone(ip: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
async function parseSPFRecord(
|
||||
domain: string,
|
||||
visited = new Set<string>(),
|
||||
lookupCount = { count: 0 },
|
||||
): Promise<any> {
|
||||
async function parseSPFRecord(domain: string, visited = new Set<string>(), lookupCount = { count: 0 }): Promise<any> {
|
||||
if (visited.has(domain) || lookupCount.count > 10) {
|
||||
return { error: 'SPF lookup limit exceeded or circular reference' };
|
||||
}
|
||||
@@ -531,11 +527,7 @@ async function checkNSandSOA(domain: string): Promise<any> {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkDNSSECADFlag(
|
||||
name: string,
|
||||
type: keyof typeof DNS_TYPES,
|
||||
opts: ResolverOpts = {},
|
||||
): Promise<any> {
|
||||
async function checkDNSSECADFlag(name: string, type: keyof typeof DNS_TYPES, opts: ResolverOpts = {}): Promise<any> {
|
||||
const { doh = 'cloudflare', timeoutMs = 3500 } = opts;
|
||||
|
||||
try {
|
||||
@@ -710,13 +702,7 @@ function formatDuration(seconds: number): string {
|
||||
return `${Math.floor(seconds / 86400)}d ${Math.floor((seconds % 86400) / 3600)}h`;
|
||||
}
|
||||
|
||||
function getSOARecommendations(
|
||||
refresh: number,
|
||||
retry: number,
|
||||
expire: number,
|
||||
minimum: number,
|
||||
ttl: number,
|
||||
): any[] {
|
||||
function getSOARecommendations(refresh: number, retry: number, expire: number, minimum: number, ttl: number): any[] {
|
||||
const recommendations = [];
|
||||
|
||||
if (refresh < 3600) {
|
||||
|
||||
@@ -205,9 +205,8 @@
|
||||
}
|
||||
).serialAnalysis}
|
||||
{@const soaData = (results as { soa?: { mname?: string; rname?: string; ttl?: number } }).soa}
|
||||
{@const timingData = (
|
||||
results as { soa?: { refresh?: number; retry?: number; expire?: number; minimum?: number } }
|
||||
).soa}
|
||||
{@const timingData = (results as { soa?: { refresh?: number; retry?: number; expire?: number; minimum?: number } })
|
||||
.soa}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>SOA Analysis for {results.name}</h3>
|
||||
|
||||
@@ -360,7 +360,9 @@
|
||||
<!-- Includes -->
|
||||
{#if results.expanded.includes.length > 0}
|
||||
{@const spfIncludes = (
|
||||
results as { expanded: { includes: Array<{ domain: string; result: { record?: string; error?: string } }> } }
|
||||
results as {
|
||||
expanded: { includes: Array<{ domain: string; result: { record?: string; error?: string } }> };
|
||||
}
|
||||
).expanded}
|
||||
<div class="includes-section">
|
||||
<h5>Included SPF Policies</h5>
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
}
|
||||
|
||||
const dnsGenerators = extractNavItems(
|
||||
(
|
||||
((
|
||||
SUB_NAV['/dns']?.find((section) => 'title' in section && section.title === 'Record Generators') as {
|
||||
items?: unknown[];
|
||||
}
|
||||
)?.items as (NavItem | NavGroup)[] || [],
|
||||
)?.items as (NavItem | NavGroup)[]) || [],
|
||||
);
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user