mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-24 23:00:22 +03:00
Feat: Builds DHCP Option 43 Generator (#15)
This commit is contained in:
1 parent
2e4bb2496d
commit
e849ead8ea
7 files changed
+1476
-1
No files matched your search
@@ -40,7 +40,7 @@
|
||||
|
||||
secondaryDropdownPositions = {
|
||||
...secondaryDropdownPositions,
|
||||
[title]: spaceOnRight < 330 ? 'left' : 'right'
|
||||
[title]: spaceOnRight < 330 ? 'left' : 'right',
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,663 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
generateOption43,
|
||||
parseIPList,
|
||||
isValidIPv4,
|
||||
VENDOR_INFO,
|
||||
type VendorType,
|
||||
type Option43Result,
|
||||
} from '$lib/utils/dhcp-option43';
|
||||
import { useClipboard, useExamples } from '$lib/composables';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
|
||||
let vendorType = $state<VendorType>('cisco-catalyst');
|
||||
let ipInput = $state('');
|
||||
let result = $state<Option43Result | null>(null);
|
||||
let errors = $state<string[]>([]);
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const vendorInfo = $derived(VENDOR_INFO[vendorType]);
|
||||
|
||||
const examplesList = [
|
||||
{
|
||||
vendor: 'cisco-catalyst' as VendorType,
|
||||
ips: '192.168.1.10\n192.168.1.11',
|
||||
description: 'Cisco Catalyst with dual controllers',
|
||||
},
|
||||
{
|
||||
vendor: 'cisco-meraki' as VendorType,
|
||||
ips: '192.168.10.5',
|
||||
description: 'Single Meraki cloud controller',
|
||||
},
|
||||
{
|
||||
vendor: 'ruckus-smartzone' as VendorType,
|
||||
ips: '10.0.0.100',
|
||||
description: 'Ruckus SmartZone controller',
|
||||
},
|
||||
{
|
||||
vendor: 'aruba' as VendorType,
|
||||
ips: '172.16.1.50',
|
||||
description: 'Aruba wireless controller',
|
||||
},
|
||||
{
|
||||
vendor: 'unifi' as VendorType,
|
||||
ips: '192.168.1.20',
|
||||
description: 'UniFi Network Controller',
|
||||
},
|
||||
{
|
||||
vendor: 'ruckus-zonedirector' as VendorType,
|
||||
ips: '10.50.100.200',
|
||||
description: 'Ruckus ZoneDirector (legacy)',
|
||||
},
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
function generate() {
|
||||
errors = [];
|
||||
result = null;
|
||||
|
||||
const ips = parseIPList(ipInput);
|
||||
|
||||
if (ips.length === 0) {
|
||||
errors = ['Please enter at least one IP address'];
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate each IP
|
||||
const invalidIPs = ips.filter((ip) => !isValidIPv4(ip));
|
||||
if (invalidIPs.length > 0) {
|
||||
errors = [`Invalid IP address format: ${invalidIPs.join(', ')}`];
|
||||
return;
|
||||
}
|
||||
|
||||
// Check max IPs for vendor
|
||||
if (ips.length > vendorInfo.maxIPs) {
|
||||
errors = [
|
||||
`${vendorInfo.name} supports maximum ${vendorInfo.maxIPs} controller${vendorInfo.maxIPs > 1 ? 's' : ''}. You entered ${ips.length}.`,
|
||||
];
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
result = generateOption43(vendorType, ips);
|
||||
} catch (error) {
|
||||
errors = [error instanceof Error ? error.message : 'Unknown error occurred'];
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
vendorType = example.vendor;
|
||||
ipInput = example.ips;
|
||||
examples.select(index);
|
||||
generate();
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Examples -->
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
getLabel={(ex) => VENDOR_INFO[ex.vendor].name}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Generate Option 43 for ${VENDOR_INFO[ex.vendor].name}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>Generator Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<section class="inputs">
|
||||
<div class="input-group">
|
||||
<label for="vendor">
|
||||
<Icon name="wifi" size="sm" />
|
||||
Wireless Controller Vendor
|
||||
</label>
|
||||
<select
|
||||
id="vendor"
|
||||
bind:value={vendorType}
|
||||
onchange={() => {
|
||||
result = null;
|
||||
examples.clear();
|
||||
}}
|
||||
>
|
||||
{#each Object.entries(VENDOR_INFO) as [value, info] (value)}
|
||||
<option {value}>{info.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<span class="help-text">{vendorInfo.description}</span>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="ip-input">
|
||||
<Icon name="network" size="sm" />
|
||||
Controller IP Address{vendorInfo.maxIPs > 1 ? 'es' : ''}
|
||||
<span class="label-hint">
|
||||
(max {vendorInfo.maxIPs})
|
||||
</span>
|
||||
</label>
|
||||
<textarea
|
||||
id="ip-input"
|
||||
bind:value={ipInput}
|
||||
placeholder={`Enter IP address${vendorInfo.maxIPs > 1 ? 'es' : ''} (one per line or comma-separated)\ne.g., 192.168.1.10, 192.168.1.11`}
|
||||
rows="3"
|
||||
onchange={() => examples.clear()}
|
||||
></textarea>
|
||||
<div class="input-actions">
|
||||
<button type="button" class="btn-primary" onclick={generate}>
|
||||
<Icon name="zap" size="sm" />
|
||||
Generate
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if errors.length > 0}
|
||||
<div class="errors">
|
||||
{#each errors as error, i (i)}
|
||||
<div class="error-message">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
{error}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if result}
|
||||
<div class="card results">
|
||||
<h3>Generated Option 43 Values</h3>
|
||||
|
||||
{#if result.iosCommand && result.workings}
|
||||
<div class="ios-command-section">
|
||||
<div class="ios-header">
|
||||
<h4>
|
||||
<Icon name="terminal" size="sm" />
|
||||
{result.commandLabel || 'DHCP Server Command'}
|
||||
</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('ios')}
|
||||
onclick={() => clipboard.copy(result!.iosCommand!, 'ios')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('ios') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('ios') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<pre class="ios-command">{result.iosCommand}</pre>
|
||||
|
||||
<div class="workings">
|
||||
<h5>How this value is calculated:</h5>
|
||||
<ul>
|
||||
{#each result.workings as working, i (i)}
|
||||
<li>{working}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="explanation">
|
||||
<Icon name="info" size="sm" />
|
||||
<p>{result.explanation}</p>
|
||||
</div>
|
||||
|
||||
<div class="output-formats">
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>Hexadecimal String</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('hex')}
|
||||
onclick={() => clipboard.copy(result!.hex, 'hex')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('hex') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('hex') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<code class="output-value">{result.hex}</code>
|
||||
<p class="format-hint">Raw hexadecimal - used in most DHCP server configurations</p>
|
||||
</div>
|
||||
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>Colon-Separated Hex</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('colonHex')}
|
||||
onclick={() => clipboard.copy(result!.colonHex, 'colonHex')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('colonHex') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('colonHex') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<code class="output-value">{result.colonHex}</code>
|
||||
<p class="format-hint">Used by Infoblox and some network appliances</p>
|
||||
</div>
|
||||
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>Windows DHCP Binary</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('windows')}
|
||||
onclick={() => clipboard.copy(result!.windowsBinary, 'windows')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('windows') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('windows') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<code class="output-value">{result.windowsBinary}</code>
|
||||
<p class="format-hint">Enter in Windows DHCP Server's Binary field for Option 43</p>
|
||||
</div>
|
||||
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>ISC DHCP Configuration</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('isc')}
|
||||
onclick={() => clipboard.copy(result!.iscDhcp, 'isc')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('isc') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('isc') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<pre class="output-value code-block">{result.iscDhcp}</pre>
|
||||
<p class="format-hint">Add to dhcpd.conf for ISC DHCP server</p>
|
||||
</div>
|
||||
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>Mikrotik Configuration</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('mikrotik')}
|
||||
onclick={() => clipboard.copy(result!.mikrotik, 'mikrotik')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('mikrotik') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('mikrotik') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<code class="output-value">{result.mikrotik}</code>
|
||||
<p class="format-hint">RouterOS DHCP option configuration command</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card info">
|
||||
<h3>Important Notes</h3>
|
||||
<ul class="notes-list">
|
||||
<li>
|
||||
<strong>DHCP Option 43</strong> is vendor-specific and must match the AP manufacturer's expected format
|
||||
</li>
|
||||
<li>
|
||||
Some vendors require <strong>Option 60</strong> (Vendor Class Identifier) to be set in addition to Option 43
|
||||
</li>
|
||||
<li>Ensure controller IPs are reachable from the AP management network</li>
|
||||
<li>
|
||||
For high availability, configure <strong>multiple controller IPs</strong> when supported
|
||||
</li>
|
||||
<li>Changes to DHCP options require AP to renew lease or reboot to take effect</li>
|
||||
<li>Always test in a controlled environment before deploying to production networks</li>
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
.input-card {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--bg-secondary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-lg);
|
||||
border: 1px solid var(--border-primary);
|
||||
|
||||
h3 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
margin: 0 0 var(--spacing-md);
|
||||
font-size: 1.25rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.inputs {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
|
||||
label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.label-hint {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 400;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
select,
|
||||
textarea {
|
||||
padding: var(--spacing-sm);
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
color: var(--text-primary);
|
||||
font-family: inherit;
|
||||
font-size: 0.9375rem;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary), transparent 90%);
|
||||
}
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.help-text {
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.input-actions {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
justify-content: flex-end;
|
||||
margin: var(--spacing-sm) auto 0 auto;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--font-size-md);
|
||||
font-weight: 500;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
background: var(--color-primary);
|
||||
color: var(--bg-primary);
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--color-primary), black 10%);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
}
|
||||
|
||||
.errors {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.error-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background: color-mix(in srgb, var(--color-error), transparent 90%);
|
||||
border-left: 3px solid var(--color-error);
|
||||
border-radius: var(--radius-md);
|
||||
color: var(--color-error);
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
.results {
|
||||
animation: slideIn 0.3s ease-out;
|
||||
background: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.ios-command-section {
|
||||
padding: var(--spacing-md);
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--color-success), transparent 95%),
|
||||
color-mix(in srgb, var(--color-success), transparent 98%)
|
||||
);
|
||||
border-left: 3px solid var(--color-success);
|
||||
border-radius: var(--radius-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.ios-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
|
||||
h4 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.ios-command {
|
||||
display: block;
|
||||
padding: var(--spacing-md);
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-success);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-x: auto;
|
||||
margin: 0 0 var(--spacing-md);
|
||||
}
|
||||
|
||||
.workings {
|
||||
h5 {
|
||||
margin: 0 0 var(--spacing-xs);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
padding-left: var(--spacing-lg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
|
||||
li {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.explanation {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-md);
|
||||
background: color-mix(in srgb, var(--color-info), transparent 92%);
|
||||
border-left: 3px solid var(--color-info);
|
||||
border-radius: var(--radius-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.output-formats {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.output-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.output-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
h4 {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background: transparent;
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--surface-hover);
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
&.copied {
|
||||
background: color-mix(in srgb, var(--color-success), transparent 90%);
|
||||
border-color: var(--color-success);
|
||||
color: var(--color-success);
|
||||
}
|
||||
}
|
||||
|
||||
.output-value {
|
||||
padding: var(--spacing-md);
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-primary);
|
||||
word-break: break-all;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.code-block {
|
||||
white-space: pre;
|
||||
word-break: normal;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.format-hint {
|
||||
margin: 0;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.info {
|
||||
margin-top: var(--spacing-lg);
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 95%);
|
||||
border-color: var(--color-warning);
|
||||
h3 {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
.notes-list {
|
||||
padding-left: var(--spacing-lg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
|
||||
li {
|
||||
line-height: 1.6;
|
||||
color: var(--text-primary);
|
||||
|
||||
strong {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.card {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.input-actions {
|
||||
flex-direction: column;
|
||||
button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.output-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-xs);
|
||||
|
||||
.copy-btn {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -306,6 +306,8 @@ export const iconMap: Record<string, string> = {
|
||||
docker: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Free v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M349.9 300.3L283.8 300.3L283.8 240.9L349.9 240.9L349.9 300.3zM349.9 96L283.8 96L283.8 156.7L349.9 156.7L349.9 96zM428.1 240.8L362 240.8L362 300.2L428.1 300.2L428.1 240.8zM271.8 168.7L205.7 168.7L205.7 228.8L271.8 228.8L271.8 168.7zM349.9 168.7L283.8 168.7L283.8 228.8L349.9 228.8L349.9 168.7zM626.7 268.7C612.3 259 579.1 255.5 553.6 260.3C550.3 236.3 536.9 215.4 512.5 196.6L498.5 187.3L489.2 201.3C470.8 229.1 465.8 274.9 485.5 305.1C476.8 309.8 459.7 316.2 437.1 315.8L2.4 315.8C-6.3 366.6 8.2 432.6 46.4 477.9C83.5 521.8 139.1 544.1 211.8 544.1C369.2 544.1 485.7 471.6 540.2 339.9C561.6 340.3 607.8 340 631.5 294.7C633 292.2 638.1 281.5 640 277.6L626.7 268.7zM115.6 240.8L49.6 240.8L49.6 300.2L115.7 300.2L115.7 240.8L115.6 240.8zM193.7 240.8L127.6 240.8L127.6 300.2L193.7 300.2L193.7 240.8zM271.8 240.8L205.7 240.8L205.7 300.2L271.8 300.2L271.8 240.8zM193.7 168.7L127.6 168.7L127.6 228.8L193.7 228.8L193.7 168.7z"/></svg>`,
|
||||
headset: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M144 352C144 325.5 165.5 304 192 304L208 304L208 400L192 400C165.5 400 144 378.5 144 352zM432 304L448 304C474.5 304 496 325.5 496 352C496 378.5 474.5 400 448 400L432 400L432 304z"/><path d="M145.1 268.2C154.9 180.3 229.5 112 320 112C410.5 112 485.1 180.3 494.9 268.2C481 260.4 465 256 448 256L432 256C405.5 256 384 277.5 384 304L384 400C384 426.5 405.5 448 432 448L448 448C465.5 448 481.9 443.3 496 435.2L496 456.1C496 495.9 463.7 528.1 424 528.1L384 528.1L384 528.1C384 501.6 362.5 480.1 336 480.1L304 480.1C277.5 480.1 256 501.6 256 528.1C256 554.6 277.5 576.1 304 576.1C348 576.1 340 576.1 423.9 576.2C490.2 576.2 544 522.5 544 456.2L544 288C544 164.3 443.7 64 320 64C196.3 64 96 164.3 96 288L96 352C96 405 139 448 192 448L208 448C234.5 448 256 426.5 256 400L256 304C256 277.5 234.5 256 208 256L192 256C175 256 159 260.4 145.1 268.2zM448 304C474.5 304 496 325.5 496 352C496 378.5 474.5 400 448 400L432 400L432 304L448 304zM144 352C144 325.5 165.5 304 192 304L208 304L208 400L192 400C165.5 400 144 378.5 144 352z"/></svg>`,
|
||||
template: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M80 288L80 409.6C92 403.5 105.6 400 120 400C160.2 400 194.1 427 204.6 463.8C228.2 463.8 251.7 463.8 275.3 464C285.8 427 319.8 400 360 400C362.7 400 365.4 400.1 368 400.4L368 352L240 352C233.6 352 227.5 349.5 223 345L150 272L95.9 272C87.1 272 79.9 279.2 79.9 288z"/><path d="M528 88C528 74.7 517.3 64 504 64C490.7 64 480 74.7 480 88L480 520C480 533.3 490.7 544 504 544L584 544C597.3 544 608 533.3 608 520C608 506.7 597.3 496 584 496L528 496L528 88zM80 488C80 465.9 97.9 448 120 448C142.1 448 160 465.9 160 488C160 510.1 142.1 528 120 528C97.9 528 80 510.1 80 488zM32 288L32 488C32 536.6 71.4 576 120 576C160.3 576 194.2 548.9 204.7 512L275.3 512C285.7 548.9 319.7 576 360 576C408.6 576 448 536.6 448 488C448 460.7 435.5 436.3 416 420.1L416 330.1C416 320.1 413.9 310.2 409.9 301.1L332.3 124.7C324.6 107.2 307.4 96 288.3 96L176 96C149.5 96 128 117.5 128 144L128 224L96 224C60.7 224 32 252.7 32 288zM368 400.4C365.4 400.2 362.7 400 360 400C319.7 400 285.8 427.1 275.3 464L204.7 464C194.3 427.1 160.3 400 120 400C105.6 400 92 403.5 80 409.6L80 288C80 279.2 87.2 272 96 272L150.1 272L223.1 345C227.6 349.5 233.7 352 240.1 352L368.1 352L368.1 400.4zM358.7 304L249.9 304L176.9 231C176.6 230.7 176.3 230.4 175.9 230.1L175.9 144L288.2 144L358.6 304zM320 488C320 465.9 337.9 448 360 448C382.1 448 400 465.9 400 488C400 510.1 382.1 528 360 528C337.9 528 320 510.1 320 488z"/></svg>`,
|
||||
dhcp: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M139.2 212C132.6 223.5 136.5 238.2 148 244.8C159.5 251.4 174.2 247.5 180.8 236C187.4 224.5 183.5 209.8 172 203.2C160.5 196.6 145.8 200.5 139.2 212zM139.2 428C145.8 439.5 160.5 443.4 172 436.8C183.5 430.2 187.4 415.5 180.8 404C174.2 392.5 159.5 388.6 148 395.2C136.5 401.8 132.6 416.5 139.2 428zM296 128C296 141.3 306.7 152 320 152C333.3 152 344 141.3 344 128C344 114.7 333.3 104 320 104C306.7 104 296 114.7 296 128zM296 320C296 333.3 306.7 344 320 344C333.3 344 344 333.3 344 320C344 306.7 333.3 296 320 296C306.7 296 296 306.7 296 320zM296 512C296 525.3 306.7 536 320 536C333.3 536 344 525.3 344 512C344 498.7 333.3 488 320 488C306.7 488 296 498.7 296 512zM459.2 236C465.8 247.5 480.5 251.4 492 244.8C503.5 238.2 507.4 223.5 500.8 212C494.2 200.5 479.5 196.6 468 203.2C456.5 209.8 452.6 224.5 459.2 236zM459.2 404C452.6 415.5 456.5 430.2 468 436.8C479.5 443.4 494.2 439.5 500.8 428C507.4 416.5 503.5 401.8 492 395.2C480.5 388.6 465.8 392.5 459.2 404z"/><path d="M320 152C333.3 152 344 141.3 344 128C344 114.7 333.3 104 320 104C306.7 104 296 114.7 296 128C296 141.3 306.7 152 320 152zM384 128C384 154.9 367.5 177.9 344 187.3L344 260.6C367.5 270.1 384 293.1 384 319.9C384 323.3 383.7 326.6 383.2 329.9L441.4 364.8C445.9 361.4 450.8 358.7 455.9 356.6L455.9 283.3C450.7 281.2 445.9 278.5 441.4 275.1L412 292.7C407.3 276.9 398.7 262.8 387.3 251.6L416.7 234C412.7 208.6 424.4 182.3 447.9 168.6C478.5 150.9 517.7 161.4 535.3 192C552.9 222.6 542.5 261.8 511.9 279.4C509.3 280.9 506.6 282.2 503.9 283.3L503.9 356.6C506.6 357.7 509.3 359 511.9 360.5C542.5 378.2 553 417.3 535.3 447.9C517.6 478.5 478.5 489 447.9 471.3C424.3 457.7 412.7 431.3 416.7 405.9L358.5 371C354.1 374.3 349.2 377.1 344 379.2L344 452.5C367.5 462 384 485 384 511.8C384 547.1 355.3 575.8 320 575.8C284.7 575.8 256 547.1 256 511.8C256 484.9 272.5 461.9 296 452.5L296 379.2C272.5 369.7 256 346.7 256 319.9C256 316.5 256.3 313.2 256.8 309.9L198.6 275C194.1 278.4 189.2 281.1 184 283.2L184 356.5C189.1 358.6 194 361.3 198.5 364.7L227.9 347.1C232.6 362.9 241.2 377 252.6 388.2L223.2 406C227.2 431.4 215.6 457.8 192 471.4C161.4 489.1 122.3 478.6 104.6 448C86.9 417.4 97.4 378.3 128 360.6C130.6 359.1 133.3 357.8 136 356.7L136 283.4C133.3 282.3 130.6 281 128 279.5C97.4 261.8 86.9 222.6 104.6 192C122.3 161.4 161.4 150.9 192 168.6C215.6 182.2 227.2 208.6 223.2 234L281.4 268.9C285.8 265.6 290.7 262.8 295.9 260.7L295.9 187.4C272.4 177.9 255.9 154.9 255.9 128.1C255.9 92.8 284.6 64.1 319.9 64.1C355.2 64.1 383.9 92.8 383.9 128.1zM320 344C333.3 344 344 333.3 344 320C344 306.7 333.3 296 320 296C306.7 296 296 306.7 296 320C296 333.3 306.7 344 320 344zM492 244.8C503.5 238.2 507.4 223.5 500.8 212C494.2 200.5 479.5 196.6 468 203.2C456.5 209.8 452.6 224.5 459.2 236C465.8 247.5 480.5 251.4 492 244.8zM180.8 236C187.4 224.5 183.5 209.8 172 203.2C160.5 196.6 145.8 200.5 139.2 212C132.6 223.5 136.5 238.2 148 244.8C159.5 251.4 174.2 247.5 180.8 236zM344 512C344 498.7 333.3 488 320 488C306.7 488 296 498.7 296 512C296 525.3 306.7 536 320 536C333.3 536 344 525.3 344 512zM139.2 428C145.8 439.5 160.5 443.4 172 436.8C183.5 430.2 187.4 415.5 180.8 404C174.2 392.5 159.5 388.6 148 395.2C136.5 401.8 132.6 416.5 139.2 428zM492 395.2C480.5 388.6 465.8 392.5 459.2 404C452.6 415.5 456.5 430.2 468 436.8C479.5 443.4 494.2 439.5 500.8 428C507.4 416.5 503.5 401.8 492 395.2z"/></svg>`,
|
||||
router: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112.2 416L112.2 480C112.2 488.8 119.4 496 128.2 496L512.2 496C521 496 528.2 488.8 528.2 480L528.2 416C528.2 407.2 521 400 512.2 400L128.2 400C119.4 400 112.2 407.2 112.2 416zM208.2 448C208.2 461.3 197.5 472 184.2 472C170.9 472 160.2 461.3 160.2 448C160.2 434.7 170.9 424 184.2 424C197.5 424 208.2 434.7 208.2 448zM304.2 448C304.2 461.3 293.5 472 280.2 472C266.9 472 256.2 461.3 256.2 448C256.2 434.7 266.9 424 280.2 424C293.5 424 304.2 434.7 304.2 448z"/><path d="M384.2 112C443 112 496.7 133.8 537.6 169.9C547.5 178.7 562.7 177.7 571.5 167.8C580.3 157.9 579.3 142.7 569.4 133.9C520 90.4 455.2 64 384.2 64C313.2 64 248.5 90.4 199.1 133.9C189.2 142.7 188.2 157.8 197 167.8C205.8 177.8 220.9 178.7 230.9 169.9C271.8 133.8 325.4 112 384.2 112zM408.2 312C408.2 298.7 397.5 288 384.2 288C370.9 288 360.2 298.7 360.2 312L360.2 352L128.2 352C92.9 352 64.2 380.7 64.2 416L64.2 480C64.2 515.3 92.9 544 128.2 544L512.2 544C547.5 544 576.2 515.3 576.2 480L576.2 416C576.2 380.7 547.5 352 512.2 352L408.2 352L408.2 312zM128.2 400L512.2 400C521 400 528.2 407.2 528.2 416L528.2 480C528.2 488.8 521 496 512.2 496L128.2 496C119.4 496 112.2 488.8 112.2 480L112.2 416C112.2 407.2 119.4 400 128.2 400zM308.7 250.7C329.4 234 355.6 224 384.2 224C412.8 224 439.1 234 459.7 250.7C470 259 485.1 257.5 493.5 247.2C501.9 236.9 500.3 221.8 490 213.4C461.1 190 424.2 176 384.2 176C344.2 176 307.4 190 278.5 213.4C268.2 221.7 266.6 236.9 275 247.2C283.4 257.5 298.5 259.1 308.8 250.7zM160.2 448C160.2 461.3 170.9 472 184.2 472C197.5 472 208.2 461.3 208.2 448C208.2 434.7 197.5 424 184.2 424C170.9 424 160.2 434.7 160.2 448zM280.2 424C266.9 424 256.2 434.7 256.2 448C256.2 461.3 266.9 472 280.2 472C293.5 472 304.2 461.3 304.2 448C304.2 434.7 293.5 424 280.2 424z"/></svg>`,
|
||||
// 'mail-check': ``,
|
||||
// 'eye': ``,
|
||||
// 'star': ``,
|
||||
|
||||
@@ -155,6 +155,30 @@ export const TOP_NAV: NavItem[] = [
|
||||
'domain',
|
||||
],
|
||||
},
|
||||
{
|
||||
href: makePath('/dhcp'),
|
||||
label: 'DHCP',
|
||||
description: 'DHCP option generators for wireless controllers and network configuration',
|
||||
keywords: [
|
||||
'dhcp',
|
||||
'option',
|
||||
'43',
|
||||
'vendor',
|
||||
'specific',
|
||||
'wireless',
|
||||
'controller',
|
||||
'cisco',
|
||||
'aruba',
|
||||
'ruckus',
|
||||
'unifi',
|
||||
'ap',
|
||||
'discovery',
|
||||
'capwap',
|
||||
'lwapp',
|
||||
'configuration',
|
||||
'network',
|
||||
],
|
||||
},
|
||||
{
|
||||
href: makePath('/diagnostics'),
|
||||
label: 'Lookups',
|
||||
@@ -776,6 +800,38 @@ export const SUB_NAV: Record<string, (NavItem | NavGroup)[]> = {
|
||||
],
|
||||
},
|
||||
],
|
||||
'/dhcp': [
|
||||
{
|
||||
href: makePath('/dhcp/option-43'),
|
||||
label: 'Option 43 Generator',
|
||||
description: 'Generate DHCP Option 43 for wireless controller discovery (Cisco, Aruba, Ruckus, UniFi)',
|
||||
icon: 'router',
|
||||
featured: true,
|
||||
keywords: [
|
||||
'dhcp',
|
||||
'option',
|
||||
'43',
|
||||
'wireless',
|
||||
'controller',
|
||||
'cisco',
|
||||
'catalyst',
|
||||
'meraki',
|
||||
'aruba',
|
||||
'ruckus',
|
||||
'smartzone',
|
||||
'zonedirector',
|
||||
'unifi',
|
||||
'extreme',
|
||||
'vendor-specific',
|
||||
'ap',
|
||||
'discovery',
|
||||
'capwap',
|
||||
'lwapp',
|
||||
'access point',
|
||||
'wlc',
|
||||
],
|
||||
},
|
||||
],
|
||||
'/dns': [
|
||||
{
|
||||
href: makePath('/dns/generators'),
|
||||
|
||||
@@ -0,0 +1,378 @@
|
||||
/**
|
||||
* DHCP Option 43 - Vendor-Specific Information
|
||||
*
|
||||
* Utilities for generating DHCP Option 43 values for wireless controller discovery.
|
||||
* Different vendors encode controller IP addresses in different formats.
|
||||
*/
|
||||
|
||||
export type VendorType =
|
||||
| 'cisco-catalyst'
|
||||
| 'cisco-meraki'
|
||||
| 'ruckus-smartzone'
|
||||
| 'ruckus-zonedirector'
|
||||
| 'aruba'
|
||||
| 'unifi'
|
||||
| 'extreme'
|
||||
| 'generic';
|
||||
|
||||
export interface Option43Result {
|
||||
hex: string;
|
||||
colonHex: string;
|
||||
windowsBinary: string;
|
||||
iscDhcp: string;
|
||||
infoblox: string;
|
||||
mikrotik: string;
|
||||
explanation: string;
|
||||
subOption?: number;
|
||||
iosCommand?: string;
|
||||
commandLabel?: string;
|
||||
workings?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert IPv4 address to hexadecimal format
|
||||
* Example: "192.168.10.5" -> "c0a80a05"
|
||||
*/
|
||||
export function ipToHex(ip: string): string {
|
||||
return ip
|
||||
.split('.')
|
||||
.map((octet) => {
|
||||
const num = parseInt(octet, 10);
|
||||
return num.toString(16).padStart(2, '0');
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert IPv4 address to ASCII hexadecimal format (for Ruckus)
|
||||
* Example: "192.168.10.5" -> "3139322e3136382e31302e35"
|
||||
* Each character (including dots) is converted to its ASCII hex value
|
||||
*/
|
||||
export function ipToAsciiHex(ip: string): string {
|
||||
return ip
|
||||
.split('')
|
||||
.map((char) => char.charCodeAt(0).toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert hex string to colon-separated format
|
||||
* Example: "f108c0a80a05" -> "f1:08:c0:a8:0a:05"
|
||||
*/
|
||||
export function hexToColonSeparated(hex: string): string {
|
||||
return hex.match(/.{1,2}/g)?.join(':') || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert hex string to space-separated pairs for Windows DHCP
|
||||
* Example: "f108c0a80a05" -> "f1 08 c0 a8 0a 05"
|
||||
*/
|
||||
export function hexToWindowsBinary(hex: string): string {
|
||||
return hex.match(/.{1,2}/g)?.join(' ') || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Cisco Option 43 (for Catalyst and legacy WLC)
|
||||
* Format: Type (0xF1) + Length (num of IPs * 4) + IP addresses in hex
|
||||
*/
|
||||
export function generateCiscoOption43(ips: string[]): Option43Result {
|
||||
const type = 'f1'; // Sub-option 241
|
||||
const length = (ips.length * 4).toString(16).padStart(2, '0');
|
||||
const ipHexValues = ips.map((ip) => ipToHex(ip)).join('');
|
||||
const hex = type + length + ipHexValues;
|
||||
|
||||
const explanation = `Cisco uses sub-option 0xF1 (241). Length is ${ips.length} × 4 = ${ips.length * 4} bytes. IP addresses are encoded as hexadecimal octets.`;
|
||||
|
||||
const workings = [
|
||||
`Option 43 static prefix for Cisco Wireless LAN Controllers: f1 (hex)`,
|
||||
`IP count: ${ips.length}`,
|
||||
`IP count × 4 bytes (hex): ${length}`,
|
||||
...ips.map((ip) => `IP ${ip} => ${ipToHex(ip)} (hex)`),
|
||||
];
|
||||
|
||||
return {
|
||||
hex,
|
||||
colonHex: hexToColonSeparated(hex),
|
||||
windowsBinary: hexToWindowsBinary(hex),
|
||||
iscDhcp: `option space Cisco_LWAPP_AP;\noption Cisco_LWAPP_AP.server-address code 241 = array of ip-address;\noption local-encapsulation code 43 = encapsulate Cisco_LWAPP_AP;\noption Cisco_LWAPP_AP.server-address ${ips.join(', ')};`,
|
||||
infoblox: hexToColonSeparated(hex),
|
||||
mikrotik: `option code=43 name=cisco-capwap value='${hex}'`,
|
||||
explanation,
|
||||
subOption: 241,
|
||||
iosCommand: `ip dhcp pool <POOL_NAME>\n option 43 hex ${hex}`,
|
||||
commandLabel: 'Cisco IOS/IOS-XE DHCP Server',
|
||||
workings,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Cisco Meraki Option 43
|
||||
* Meraki uses a simple ASCII string format
|
||||
*/
|
||||
export function generateMerakiOption43(ips: string[]): Option43Result {
|
||||
// Meraki uses comma-separated IP addresses in ASCII
|
||||
const asciiString = ips.join(',');
|
||||
const hex = asciiString
|
||||
.split('')
|
||||
.map((char) => char.charCodeAt(0).toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
|
||||
const explanation = `Cisco Meraki uses ASCII-encoded comma-separated IP addresses. Each character is converted to hexadecimal.`;
|
||||
|
||||
const workings = [
|
||||
`Cisco Meraki uses ASCII-encoded IP addresses`,
|
||||
`IP count: ${ips.length}`,
|
||||
`Concatenated IP string: ${asciiString} (length: ${asciiString.length} chars)`,
|
||||
`Which translates to: ${hex} (hex)`,
|
||||
];
|
||||
|
||||
return {
|
||||
hex,
|
||||
colonHex: hexToColonSeparated(hex),
|
||||
windowsBinary: hexToWindowsBinary(hex),
|
||||
iscDhcp: `option vendor-encapsulated-options "${asciiString}";`,
|
||||
infoblox: hexToColonSeparated(hex),
|
||||
mikrotik: `option code=43 name=meraki value='"${asciiString}"'`,
|
||||
explanation,
|
||||
iosCommand: `ip dhcp pool <POOL_NAME>\n option 43 hex ${hex}`,
|
||||
commandLabel: 'Cisco IOS/IOS-XE DHCP Server',
|
||||
workings,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Ruckus Option 43
|
||||
* Format: Vendor code (03 or 06) + Length in hex + IP in ASCII hex
|
||||
*/
|
||||
export function generateRuckusOption43(ips: string[], type: 'smartzone' | 'zonedirector'): Option43Result {
|
||||
const vendorCode = type === 'smartzone' ? '06' : '03';
|
||||
const ip = ips[0]; // Ruckus typically uses single controller
|
||||
const asciiHex = ipToAsciiHex(ip);
|
||||
const length = (asciiHex.length / 2).toString(16).padStart(2, '0');
|
||||
const hex = vendorCode + length + asciiHex;
|
||||
|
||||
const explanation = `Ruckus uses vendor code ${vendorCode} (${type === 'smartzone' ? 'SmartZone' : 'ZoneDirector'}). Length is ${asciiHex.length / 2} bytes. IP address is encoded as ASCII characters converted to hexadecimal.`;
|
||||
|
||||
const vendorName = type === 'smartzone' ? 'Ruckus Wireless (SmartZone)' : 'Ruckus Wireless (ZoneDirector)';
|
||||
const workings = [
|
||||
`Option 43 static prefix for ${vendorName}: ${vendorCode} (hex)`,
|
||||
`IP count: 1`,
|
||||
`Concatenated IP string: ${ip} (length: ${ip.length}/0x${ip.length.toString(16).padStart(2, '0')} chars)`,
|
||||
`Which translates to: ${asciiHex} (hex)`,
|
||||
];
|
||||
|
||||
// Ruckus controllers can act as DHCP servers
|
||||
const ruckusCommand =
|
||||
type === 'smartzone'
|
||||
? `config\n dhcp-profile <PROFILE_NAME>\n option43 sub-option ${parseInt(vendorCode, 16)} type string ${ip}\n end`
|
||||
: `config\n dhcp-profile <PROFILE_NAME>\n option43 sub-option ${parseInt(vendorCode, 16)} type string ${ip}\n end`;
|
||||
|
||||
return {
|
||||
hex,
|
||||
colonHex: hexToColonSeparated(hex),
|
||||
windowsBinary: hexToWindowsBinary(hex),
|
||||
iscDhcp: `option vendor-class-identifier "Ruckus CPE";\noption vendor-encapsulated-options ${hex};`,
|
||||
infoblox: hexToColonSeparated(hex),
|
||||
mikrotik: `option code=43 name=ruckus value='${hex}'`,
|
||||
explanation,
|
||||
subOption: parseInt(vendorCode, 16),
|
||||
iosCommand: ruckusCommand,
|
||||
commandLabel: type === 'smartzone' ? 'Ruckus SmartZone CLI' : 'Ruckus ZoneDirector CLI',
|
||||
workings,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Aruba Option 43
|
||||
* Aruba uses simple ASCII IP address format
|
||||
*/
|
||||
export function generateArubaOption43(ips: string[]): Option43Result {
|
||||
const ip = ips[0]; // Aruba typically uses single controller
|
||||
const hex = ipToAsciiHex(ip);
|
||||
|
||||
const explanation = `Aruba uses ASCII-encoded IP address. The IP ${ip} is converted directly to hexadecimal representation of ASCII characters.`;
|
||||
|
||||
const workings = [
|
||||
`Aruba uses ASCII-encoded IP address`,
|
||||
`IP count: 1`,
|
||||
`IP string: ${ip} (length: ${ip.length} chars)`,
|
||||
`Which translates to: ${hex} (hex)`,
|
||||
];
|
||||
|
||||
return {
|
||||
hex,
|
||||
colonHex: hexToColonSeparated(hex),
|
||||
windowsBinary: hexToWindowsBinary(hex),
|
||||
iscDhcp: `option vendor-class-identifier "ArubaAP";\noption vendor-encapsulated-options "${ip}";`,
|
||||
infoblox: hexToColonSeparated(hex),
|
||||
mikrotik: `option code=43 name=aruba value='"${ip}"'`,
|
||||
explanation,
|
||||
iosCommand: `ip dhcp <PROFILE_NAME>\n option 43 hex ${hex}`,
|
||||
commandLabel: 'Aruba OS Switch/Controller',
|
||||
workings,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Ubiquiti UniFi Option 43
|
||||
* Format: 01:04 + IP address in hex (single controller only)
|
||||
*/
|
||||
export function generateUniFiOption43(ip: string): Option43Result {
|
||||
const prefix = '0104'; // Type 01, Length 04
|
||||
const ipHex = ipToHex(ip);
|
||||
const hex = prefix + ipHex;
|
||||
|
||||
const explanation = `UniFi uses sub-option 01 (type) with length 04 (4 bytes). IP address is encoded as hexadecimal octets. Note: Hex must use UPPERCASE in some configurations.`;
|
||||
|
||||
const workings = [
|
||||
`UniFi uses sub-option 01 with length 04`,
|
||||
`IP count: 1`,
|
||||
`Sub-option prefix: 01 (type) + 04 (length in bytes)`,
|
||||
`IP ${ip} => ${ipHex} (hex)`,
|
||||
];
|
||||
|
||||
return {
|
||||
hex,
|
||||
colonHex: hexToColonSeparated(hex),
|
||||
windowsBinary: hexToWindowsBinary(hex),
|
||||
iscDhcp: `option space ubnt;\noption ubnt.unifi-address code 1 = ip-address;\noption local-encapsulation code 43 = encapsulate ubnt;\noption ubnt.unifi-address ${ip};`,
|
||||
infoblox: hexToColonSeparated(hex),
|
||||
mikrotik: `option code=43 name=unifi value='${hex}'`,
|
||||
explanation,
|
||||
subOption: 1,
|
||||
iosCommand: `set service dhcp-server shared-network-name <NETWORK> subnet <SUBNET> static-mapping <MAPPING> static-mapping-parameters "option ubnt-unifi-address ${ip};"`,
|
||||
commandLabel: 'UniFi EdgeRouter/USG',
|
||||
workings,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Extreme Networks (Aerohive) Option 43
|
||||
* Uses vendor class identifier and option 43
|
||||
*/
|
||||
export function generateExtremeOption43(ips: string[]): Option43Result {
|
||||
const ip = ips[0];
|
||||
const hex = ipToAsciiHex(ip);
|
||||
|
||||
const explanation = `Extreme Networks (formerly Aerohive) uses vendor class identifier with the AP model. Option 43 contains ASCII-encoded controller IP.`;
|
||||
|
||||
const workings = [
|
||||
`Extreme Networks uses ASCII-encoded IP address`,
|
||||
`IP count: 1`,
|
||||
`IP string: ${ip} (length: ${ip.length} chars)`,
|
||||
`Which translates to: ${hex} (hex)`,
|
||||
];
|
||||
|
||||
return {
|
||||
hex,
|
||||
colonHex: hexToColonSeparated(hex),
|
||||
windowsBinary: hexToWindowsBinary(hex),
|
||||
iscDhcp: `option vendor-class-identifier "HiPath AP";\noption vendor-encapsulated-options "${ip}";`,
|
||||
infoblox: hexToColonSeparated(hex),
|
||||
mikrotik: `option code=43 name=extreme value='"${ip}"'`,
|
||||
explanation,
|
||||
iosCommand: `configure dhcp-server <SERVER_NAME> dhcp-option 43 hex ${hex}`,
|
||||
commandLabel: 'Extreme Networks Switch',
|
||||
workings,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Option 43 for specified vendor
|
||||
*/
|
||||
export function generateOption43(vendor: VendorType, ips: string[]): Option43Result {
|
||||
if (ips.length === 0) {
|
||||
throw new Error('At least one IP address is required');
|
||||
}
|
||||
|
||||
switch (vendor) {
|
||||
case 'cisco-catalyst':
|
||||
return generateCiscoOption43(ips);
|
||||
case 'cisco-meraki':
|
||||
return generateMerakiOption43(ips);
|
||||
case 'ruckus-smartzone':
|
||||
return generateRuckusOption43(ips, 'smartzone');
|
||||
case 'ruckus-zonedirector':
|
||||
return generateRuckusOption43(ips, 'zonedirector');
|
||||
case 'aruba':
|
||||
return generateArubaOption43(ips);
|
||||
case 'unifi':
|
||||
return generateUniFiOption43(ips[0]);
|
||||
case 'extreme':
|
||||
return generateExtremeOption43(ips);
|
||||
case 'generic':
|
||||
// Generic TLV format with custom sub-option
|
||||
return generateCiscoOption43(ips);
|
||||
default:
|
||||
throw new Error(`Unsupported vendor: ${vendor}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate IPv4 address format
|
||||
*/
|
||||
export function isValidIPv4(ip: string): boolean {
|
||||
const octets = ip.split('.');
|
||||
if (octets.length !== 4) return false;
|
||||
|
||||
return octets.every((octet) => {
|
||||
const num = parseInt(octet, 10);
|
||||
return !isNaN(num) && num >= 0 && num <= 255 && octet === num.toString();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and validate IP address list (comma or newline separated)
|
||||
*/
|
||||
export function parseIPList(input: string): string[] {
|
||||
return input
|
||||
.split(/[,\n]+/)
|
||||
.map((ip) => ip.trim())
|
||||
.filter((ip) => ip.length > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vendor display names and descriptions
|
||||
*/
|
||||
export const VENDOR_INFO: Record<VendorType, { name: string; description: string; maxIPs: number }> = {
|
||||
'cisco-catalyst': {
|
||||
name: 'Cisco Catalyst / WLC',
|
||||
description: 'Cisco Wireless LAN Controllers and Catalyst with embedded wireless',
|
||||
maxIPs: 10,
|
||||
},
|
||||
'cisco-meraki': {
|
||||
name: 'Cisco Meraki',
|
||||
description: 'Cisco Meraki cloud-managed wireless access points',
|
||||
maxIPs: 5,
|
||||
},
|
||||
'ruckus-smartzone': {
|
||||
name: 'Ruckus SmartZone',
|
||||
description: 'Ruckus SmartZone wireless controllers (vendor code 06)',
|
||||
maxIPs: 1,
|
||||
},
|
||||
'ruckus-zonedirector': {
|
||||
name: 'Ruckus ZoneDirector',
|
||||
description: 'Ruckus ZoneDirector wireless controllers (vendor code 03)',
|
||||
maxIPs: 1,
|
||||
},
|
||||
aruba: {
|
||||
name: 'Aruba / HP Aruba',
|
||||
description: 'Aruba Networks wireless controllers',
|
||||
maxIPs: 1,
|
||||
},
|
||||
unifi: {
|
||||
name: 'Ubiquiti UniFi',
|
||||
description: 'Ubiquiti UniFi Network Controller for access points',
|
||||
maxIPs: 1,
|
||||
},
|
||||
extreme: {
|
||||
name: 'Extreme Networks',
|
||||
description: 'Extreme Networks (formerly Aerohive) wireless controllers',
|
||||
maxIPs: 1,
|
||||
},
|
||||
generic: {
|
||||
name: 'Generic / Custom',
|
||||
description: 'Generic TLV format with custom sub-option code',
|
||||
maxIPs: 10,
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
<script lang="ts">
|
||||
import DHCPOption43Generator from '$lib/components/tools/DHCPOption43Generator.svelte';
|
||||
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
|
||||
</script>
|
||||
|
||||
<ToolContentContainer
|
||||
title="DHCP Option 43 Generator"
|
||||
description="Generate vendor-specific DHCP Option 43 values for wireless controller auto-discovery. Supports Cisco, Aruba, Ruckus, UniFi, and more with multiple output formats."
|
||||
>
|
||||
<DHCPOption43Generator />
|
||||
</ToolContentContainer>
|
||||
@@ -0,0 +1,365 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
ipToHex,
|
||||
ipToAsciiHex,
|
||||
hexToColonSeparated,
|
||||
hexToWindowsBinary,
|
||||
generateCiscoOption43,
|
||||
generateMerakiOption43,
|
||||
generateRuckusOption43,
|
||||
generateArubaOption43,
|
||||
generateUniFiOption43,
|
||||
generateExtremeOption43,
|
||||
generateOption43,
|
||||
isValidIPv4,
|
||||
parseIPList,
|
||||
type VendorType,
|
||||
} from '$lib/utils/dhcp-option43';
|
||||
|
||||
describe('dhcp-option43 utilities', () => {
|
||||
describe('ipToHex', () => {
|
||||
it('should convert IPv4 address to hex', () => {
|
||||
expect(ipToHex('192.168.1.10')).toBe('c0a8010a');
|
||||
expect(ipToHex('192.168.1.11')).toBe('c0a8010b');
|
||||
expect(ipToHex('10.0.0.1')).toBe('0a000001');
|
||||
expect(ipToHex('255.255.255.255')).toBe('ffffffff');
|
||||
expect(ipToHex('0.0.0.0')).toBe('00000000');
|
||||
});
|
||||
|
||||
it('should handle single digit octets correctly', () => {
|
||||
expect(ipToHex('1.2.3.4')).toBe('01020304');
|
||||
expect(ipToHex('10.20.30.40')).toBe('0a141e28');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ipToAsciiHex', () => {
|
||||
it('should convert IP string to ASCII hex', () => {
|
||||
expect(ipToAsciiHex('192.168.10.5')).toBe('3139322e3136382e31302e35');
|
||||
expect(ipToAsciiHex('172.16.1.50')).toBe('3137322e31362e312e3530');
|
||||
});
|
||||
|
||||
it('should handle different IP lengths', () => {
|
||||
expect(ipToAsciiHex('10.0.0.1')).toBe('31302e302e302e31');
|
||||
expect(ipToAsciiHex('255.255.255.255')).toBe('3235352e3235352e3235352e323535');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hexToColonSeparated', () => {
|
||||
it('should convert hex to colon-separated format', () => {
|
||||
expect(hexToColonSeparated('f108c0a8010ac0a8010b')).toBe('f1:08:c0:a8:01:0a:c0:a8:01:0b');
|
||||
expect(hexToColonSeparated('0104c0a80114')).toBe('01:04:c0:a8:01:14');
|
||||
});
|
||||
|
||||
it('should handle odd-length hex strings', () => {
|
||||
expect(hexToColonSeparated('abc')).toBe('ab:c');
|
||||
});
|
||||
|
||||
it('should handle empty string', () => {
|
||||
expect(hexToColonSeparated('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hexToWindowsBinary', () => {
|
||||
it('should convert hex to space-separated format', () => {
|
||||
expect(hexToWindowsBinary('f108c0a8010ac0a8010b')).toBe('f1 08 c0 a8 01 0a c0 a8 01 0b');
|
||||
expect(hexToWindowsBinary('0104c0a80114')).toBe('01 04 c0 a8 01 14');
|
||||
});
|
||||
|
||||
it('should handle empty string', () => {
|
||||
expect(hexToWindowsBinary('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateCiscoOption43', () => {
|
||||
it('should generate correct hex for single IP', () => {
|
||||
const result = generateCiscoOption43(['192.168.1.10']);
|
||||
expect(result.hex).toBe('f104c0a8010a');
|
||||
expect(result.subOption).toBe(241);
|
||||
});
|
||||
|
||||
it('should generate correct hex for dual IPs', () => {
|
||||
const result = generateCiscoOption43(['192.168.1.10', '192.168.1.11']);
|
||||
expect(result.hex).toBe('f108c0a8010ac0a8010b');
|
||||
expect(result.colonHex).toBe('f1:08:c0:a8:01:0a:c0:a8:01:0b');
|
||||
expect(result.windowsBinary).toBe('f1 08 c0 a8 01 0a c0 a8 01 0b');
|
||||
});
|
||||
|
||||
it('should generate correct hex for multiple IPs', () => {
|
||||
const result = generateCiscoOption43(['10.0.0.1', '10.0.0.2', '10.0.0.3']);
|
||||
expect(result.hex).toBe('f10c0a0000010a0000020a000003');
|
||||
});
|
||||
|
||||
it('should have correct IOS command', () => {
|
||||
const result = generateCiscoOption43(['192.168.1.10']);
|
||||
expect(result.iosCommand).toContain('ip dhcp pool');
|
||||
expect(result.iosCommand).toContain('option 43 hex');
|
||||
expect(result.iosCommand).toContain('f104c0a8010a');
|
||||
expect(result.commandLabel).toBe('Cisco IOS/IOS-XE DHCP Server');
|
||||
});
|
||||
|
||||
it('should have workings array', () => {
|
||||
const result = generateCiscoOption43(['192.168.1.10', '192.168.1.11']);
|
||||
expect(result.workings).toBeDefined();
|
||||
expect(result.workings!.length).toBeGreaterThan(0);
|
||||
expect(result.workings![0]).toContain('f1');
|
||||
expect(result.workings![2]).toContain('08');
|
||||
});
|
||||
|
||||
it('should generate all output formats', () => {
|
||||
const result = generateCiscoOption43(['192.168.1.10']);
|
||||
expect(result.hex).toBeDefined();
|
||||
expect(result.colonHex).toBeDefined();
|
||||
expect(result.windowsBinary).toBeDefined();
|
||||
expect(result.iscDhcp).toBeDefined();
|
||||
expect(result.infoblox).toBeDefined();
|
||||
expect(result.mikrotik).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateMerakiOption43', () => {
|
||||
it('should generate correct ASCII hex for single IP', () => {
|
||||
const result = generateMerakiOption43(['192.168.10.5']);
|
||||
expect(result.hex).toBe('3139322e3136382e31302e35');
|
||||
});
|
||||
|
||||
it('should generate correct ASCII hex for multiple IPs', () => {
|
||||
const result = generateMerakiOption43(['192.168.1.10', '192.168.1.11']);
|
||||
// "192.168.1.10,192.168.1.11"
|
||||
expect(result.hex).toBe('3139322e3136382e312e31302c3139322e3136382e312e3131');
|
||||
});
|
||||
|
||||
it('should have correct IOS command with hex format', () => {
|
||||
const result = generateMerakiOption43(['192.168.10.5']);
|
||||
expect(result.iosCommand).toContain('option 43 hex');
|
||||
expect(result.iosCommand).not.toContain('ascii');
|
||||
});
|
||||
|
||||
it('should have workings showing ASCII conversion', () => {
|
||||
const result = generateMerakiOption43(['192.168.10.5']);
|
||||
expect(result.workings).toBeDefined();
|
||||
expect(result.workings!.some((w) => w.includes('ASCII'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateRuckusOption43', () => {
|
||||
it('should generate correct hex for SmartZone', () => {
|
||||
const result = generateRuckusOption43(['172.16.1.50'], 'smartzone');
|
||||
expect(result.hex).toBe('060b3137322e31362e312e3530');
|
||||
expect(result.subOption).toBe(6);
|
||||
});
|
||||
|
||||
it('should generate correct hex for ZoneDirector', () => {
|
||||
const result = generateRuckusOption43(['10.50.100.200'], 'zonedirector');
|
||||
expect(result.hex).toBe('030d31302e35302e3130302e323030');
|
||||
expect(result.subOption).toBe(3);
|
||||
});
|
||||
|
||||
it('should use different vendor codes', () => {
|
||||
const smartzone = generateRuckusOption43(['192.168.1.1'], 'smartzone');
|
||||
const zonedirector = generateRuckusOption43(['192.168.1.1'], 'zonedirector');
|
||||
expect(smartzone.hex.substring(0, 2)).toBe('06');
|
||||
expect(zonedirector.hex.substring(0, 2)).toBe('03');
|
||||
});
|
||||
|
||||
it('should have correct command labels', () => {
|
||||
const smartzone = generateRuckusOption43(['192.168.1.1'], 'smartzone');
|
||||
const zonedirector = generateRuckusOption43(['192.168.1.1'], 'zonedirector');
|
||||
expect(smartzone.commandLabel).toBe('Ruckus SmartZone CLI');
|
||||
expect(zonedirector.commandLabel).toBe('Ruckus ZoneDirector CLI');
|
||||
});
|
||||
|
||||
it('should have Ruckus-specific commands', () => {
|
||||
const result = generateRuckusOption43(['172.16.1.50'], 'smartzone');
|
||||
expect(result.iosCommand).toContain('dhcp-profile');
|
||||
expect(result.iosCommand).toContain('option43 sub-option');
|
||||
});
|
||||
|
||||
it('should calculate correct length', () => {
|
||||
const result = generateRuckusOption43(['172.16.1.50'], 'smartzone');
|
||||
// "172.16.1.50" is 11 characters = 0x0b
|
||||
expect(result.hex.substring(2, 4)).toBe('0b');
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateArubaOption43', () => {
|
||||
it('should generate correct ASCII hex', () => {
|
||||
const result = generateArubaOption43(['172.16.1.50']);
|
||||
expect(result.hex).toBe('3137322e31362e312e3530');
|
||||
});
|
||||
|
||||
it('should use only first IP if multiple provided', () => {
|
||||
const result = generateArubaOption43(['172.16.1.50', '172.16.1.51']);
|
||||
expect(result.hex).toBe('3137322e31362e312e3530');
|
||||
});
|
||||
|
||||
it('should have correct command format', () => {
|
||||
const result = generateArubaOption43(['172.16.1.50']);
|
||||
expect(result.iosCommand).toContain('ip dhcp');
|
||||
expect(result.iosCommand).toContain('option 43 hex');
|
||||
expect(result.commandLabel).toBe('Aruba OS Switch/Controller');
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateUniFiOption43', () => {
|
||||
it('should generate correct hex with prefix', () => {
|
||||
const result = generateUniFiOption43('192.168.1.20');
|
||||
expect(result.hex).toBe('0104c0a80114');
|
||||
expect(result.subOption).toBe(1);
|
||||
});
|
||||
|
||||
it('should start with 0104 prefix', () => {
|
||||
const result = generateUniFiOption43('10.0.0.1');
|
||||
expect(result.hex.substring(0, 4)).toBe('0104');
|
||||
});
|
||||
|
||||
it('should have EdgeRouter command format', () => {
|
||||
const result = generateUniFiOption43('192.168.1.20');
|
||||
expect(result.iosCommand).toContain('set service dhcp-server');
|
||||
expect(result.commandLabel).toBe('UniFi EdgeRouter/USG');
|
||||
});
|
||||
|
||||
it('should have correct ISC DHCP format', () => {
|
||||
const result = generateUniFiOption43('192.168.1.20');
|
||||
expect(result.iscDhcp).toContain('option space ubnt');
|
||||
expect(result.iscDhcp).toContain('encapsulate ubnt');
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateExtremeOption43', () => {
|
||||
it('should generate correct ASCII hex', () => {
|
||||
const result = generateExtremeOption43(['172.16.1.50']);
|
||||
expect(result.hex).toBe('3137322e31362e312e3530');
|
||||
});
|
||||
|
||||
it('should have Extreme-specific command', () => {
|
||||
const result = generateExtremeOption43(['172.16.1.50']);
|
||||
expect(result.iosCommand).toContain('configure dhcp-server');
|
||||
expect(result.commandLabel).toBe('Extreme Networks Switch');
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateOption43', () => {
|
||||
it('should route to correct vendor function', () => {
|
||||
const cisco = generateOption43('cisco-catalyst', ['192.168.1.10']);
|
||||
const meraki = generateOption43('cisco-meraki', ['192.168.10.5']);
|
||||
const ruckusSZ = generateOption43('ruckus-smartzone', ['10.0.0.1']);
|
||||
const ruckusZD = generateOption43('ruckus-zonedirector', ['10.0.0.1']);
|
||||
const aruba = generateOption43('aruba', ['172.16.1.50']);
|
||||
const unifi = generateOption43('unifi', ['192.168.1.20']);
|
||||
const extreme = generateOption43('extreme', ['10.0.0.1']);
|
||||
|
||||
expect(cisco.hex).toBe('f104c0a8010a');
|
||||
expect(meraki.hex).toBe('3139322e3136382e31302e35');
|
||||
expect(ruckusSZ.hex.substring(0, 2)).toBe('06');
|
||||
expect(ruckusZD.hex.substring(0, 2)).toBe('03');
|
||||
expect(aruba.hex).toBe('3137322e31362e312e3530');
|
||||
expect(unifi.hex).toBe('0104c0a80114');
|
||||
expect(extreme.hex).toBeDefined();
|
||||
});
|
||||
|
||||
it('should handle generic vendor type', () => {
|
||||
const result = generateOption43('generic', ['192.168.1.10']);
|
||||
expect(result.hex).toBe('f104c0a8010a'); // Uses Cisco format
|
||||
});
|
||||
|
||||
it('should throw error for empty IP array', () => {
|
||||
expect(() => generateOption43('cisco-catalyst', [])).toThrow('At least one IP address is required');
|
||||
});
|
||||
|
||||
it('should throw error for unsupported vendor', () => {
|
||||
expect(() => generateOption43('invalid-vendor' as VendorType, ['192.168.1.1'])).toThrow(
|
||||
'Unsupported vendor'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidIPv4', () => {
|
||||
it('should validate correct IPv4 addresses', () => {
|
||||
expect(isValidIPv4('192.168.1.1')).toBe(true);
|
||||
expect(isValidIPv4('10.0.0.1')).toBe(true);
|
||||
expect(isValidIPv4('255.255.255.255')).toBe(true);
|
||||
expect(isValidIPv4('0.0.0.0')).toBe(true);
|
||||
expect(isValidIPv4('172.16.1.50')).toBe(true);
|
||||
});
|
||||
|
||||
it('should reject invalid IPv4 addresses', () => {
|
||||
expect(isValidIPv4('256.1.1.1')).toBe(false);
|
||||
expect(isValidIPv4('192.168.1')).toBe(false);
|
||||
expect(isValidIPv4('192.168.1.1.1')).toBe(false);
|
||||
expect(isValidIPv4('192.168.-1.1')).toBe(false);
|
||||
expect(isValidIPv4('192.168.1.abc')).toBe(false);
|
||||
expect(isValidIPv4('not.an.ip.address')).toBe(false);
|
||||
});
|
||||
|
||||
it('should reject leading zeros', () => {
|
||||
expect(isValidIPv4('192.168.01.1')).toBe(false);
|
||||
expect(isValidIPv4('192.168.001.1')).toBe(false);
|
||||
});
|
||||
|
||||
it('should reject empty or invalid formats', () => {
|
||||
expect(isValidIPv4('')).toBe(false);
|
||||
expect(isValidIPv4('...')).toBe(false);
|
||||
expect(isValidIPv4('192.168.1.')).toBe(false);
|
||||
expect(isValidIPv4('.192.168.1.1')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseIPList', () => {
|
||||
it('should parse comma-separated IPs', () => {
|
||||
expect(parseIPList('192.168.1.1,192.168.1.2')).toEqual(['192.168.1.1', '192.168.1.2']);
|
||||
});
|
||||
|
||||
it('should parse newline-separated IPs', () => {
|
||||
expect(parseIPList('192.168.1.1\n192.168.1.2')).toEqual(['192.168.1.1', '192.168.1.2']);
|
||||
});
|
||||
|
||||
it('should parse mixed separators', () => {
|
||||
expect(parseIPList('192.168.1.1,192.168.1.2\n192.168.1.3')).toEqual([
|
||||
'192.168.1.1',
|
||||
'192.168.1.2',
|
||||
'192.168.1.3',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should trim whitespace', () => {
|
||||
expect(parseIPList(' 192.168.1.1 , 192.168.1.2 ')).toEqual(['192.168.1.1', '192.168.1.2']);
|
||||
});
|
||||
|
||||
it('should filter empty strings', () => {
|
||||
expect(parseIPList('192.168.1.1,,192.168.1.2')).toEqual(['192.168.1.1', '192.168.1.2']);
|
||||
expect(parseIPList('192.168.1.1\n\n192.168.1.2')).toEqual(['192.168.1.1', '192.168.1.2']);
|
||||
});
|
||||
|
||||
it('should handle single IP', () => {
|
||||
expect(parseIPList('192.168.1.1')).toEqual(['192.168.1.1']);
|
||||
});
|
||||
|
||||
it('should return empty array for empty input', () => {
|
||||
expect(parseIPList('')).toEqual([]);
|
||||
expect(parseIPList(' ')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Integration tests', () => {
|
||||
it('should produce consistent results across formats', () => {
|
||||
const result = generateCiscoOption43(['192.168.1.10', '192.168.1.11']);
|
||||
const hexPairs = result.hex.match(/.{1,2}/g) || [];
|
||||
|
||||
expect(result.colonHex).toBe(hexPairs.join(':'));
|
||||
expect(result.windowsBinary).toBe(hexPairs.join(' '));
|
||||
expect(result.infoblox).toBe(hexPairs.join(':'));
|
||||
});
|
||||
|
||||
it('should handle real-world example from user', () => {
|
||||
// User's example: 192.168.1.10, 192.168.1.11 should produce f108c0a8010ac0a8010b
|
||||
const result = generateCiscoOption43(['192.168.1.10', '192.168.1.11']);
|
||||
expect(result.hex).toBe('f108c0a8010ac0a8010b');
|
||||
});
|
||||
|
||||
it('should handle Ruckus example from user', () => {
|
||||
// User's example: 172.16.1.50 for Ruckus should produce 030b3137322e31362e312e3530
|
||||
const result = generateRuckusOption43(['172.16.1.50'], 'zonedirector');
|
||||
expect(result.hex).toBe('030b3137322e31362e312e3530');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user