commit d6da7a6a2e8b8a68d6b403852653f5f72f33c1ae Author: adrien Date: Sun May 11 23:31:27 2025 +0200 wip diff --git a/Network.php b/Network.php new file mode 100644 index 0000000..2872e5d --- /dev/null +++ b/Network.php @@ -0,0 +1,73 @@ +mask = binary_mask($cidr_mask); + $this->address = $address & $this->mask; + $this->name = $name; + } + + public function __toString(): string { + return long2ip($this->address) . " / " . cidr_mask($this->mask); + } + + public function __debugInfo(): array { + return [ + "name" => $this->name, + "ip_adress" => long2ip($this->address), + "cidr_mask" => cidr_mask($this->mask), + ]; + } + + public function contains(Network $other) { + return ($other->address & $this->mask) == $this->address; + } +} + +$networks = [ + new Network(ip2long("10.75.0.0"), 16, "Paris"), + new Network(ip2long("10.94.0.0"), 16, "Val-de-Marne"), + new Network(ip2long("10.232.0.0"), 16, "DiRIF"), + new Network(ip2long("10.75.128.0"), 22, "Miollis"), + new Network(ip2long("10.75.128.0"), 24, "Serveurs"), + new Network(ip2long("10.75.129.0"), 24, "Data"), + new Network(ip2long("10.75.8.0"), 22, "Crillon"), + new Network(ip2long("10.94.8.0"), 22, "Créteil Archives"), + new Network(ip2long("10.232.160.0"), 22, "Créteil l'Echat"), +]; + +$subnetworks = []; +foreach ($networks as $network) { + $subnetworks[] = ["network" => $network, "subnetworks" => []]; +} + +usort($subnetworks, function($a, $b) { + return $b["network"]->mask <=> $a["network"]->mask; +}); + +$networks_tree = []; + +while (count($subnetworks)) { + ["network" => $network1, "subnetworks" => $subnetworks1] = array_shift($subnetworks); + foreach($subnetworks as ["network" => $network2, "subnetworks" => &$subnetworks2]) { + if ($network2->contains($network1)) { + $subnetworks2[] = ["network" => $network1, "subnetworks" => $subnetworks1]; + continue 2; + } + } + $networks_tree[] = ["network" => $network1, "subnetworks" => $subnetworks1]; +} +var_dump($networks_tree); \ No newline at end of file diff --git a/add-network.php b/add-network.php new file mode 100644 index 0000000..bd04db1 --- /dev/null +++ b/add-network.php @@ -0,0 +1,17 @@ + [ + "min_range" => 0, + "max_range" => 4294967295 + ] +]); +$mask = filter_input(INPUT_POST, 'mask', FILTER_VALIDATE_INT, [ + "options" => [ + "min_range" => 0, + "max_range" => 32 + ] +]); + +echo long2ip($address), "/", $mask; \ No newline at end of file diff --git a/db.php b/db.php new file mode 100644 index 0000000..1446121 --- /dev/null +++ b/db.php @@ -0,0 +1,18 @@ +getMessage(); + exit(); +} + +$db->exec(<< + + + + + IPAM + + + + + + +
+
+
+
+ + +
+
+
+ +
+ +
.
+ +
.
+ +
.
+ +
+
+ +
+ +
+
/
+ +
+
+ +
+ +
+
+
+ + \ No newline at end of file diff --git a/ipam.db b/ipam.db new file mode 100644 index 0000000..e69de29