-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathip-ranges.php
More file actions
119 lines (109 loc) · 3.56 KB
/
ip-ranges.php
File metadata and controls
119 lines (109 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
require 'inc/lib.inc';
require 'header.php';
?>
<TABLE width="99%">
<TR>
<TD align="left"><H1>Display IP usage</H1>
</TR>
</TABLE>
<HR><P>
<?php
function subnet_menu()
{
$db = new DB_probind;
$db->query("SELECT domain FROM zones WHERE domain LIKE '%.in-addr.arpa' ORDER BY domain");
$domains = $db->fetchAll();
$result = "<SELECT name=\"subnet\">\n";
foreach ($domains as $domain) {
$result .= "<OPTION>$domain</OPTION>\n";
}
$result .= "</SELECT>\n";
return $result;
}
function subnet_view($subnet)
{
$db = new DB_probind;
$doms = explode(".", $subnet);
$prefix = $doms[0];
for ($i=1; $doms[$i] != "in-addr"; $i++)
$prefix = "$doms[$i].$prefix";
$db->prepare("SELECT zones.domain AS zdom, zones.id AS zid, records.domain AS rdom, records.data AS rdata
FROM zones, records WHERE zones.id = records.zone AND records.data LIKE ? ".access());
$db->execute($prefix.".%");
while ($db->next_record()) {
if ($db->Record['rdom'] == $db->Record['zdom'].".")
$descr = sprintf("<A HREF=\"zones.php?zone=%d\">%s</A>",
$db->Record['zid'], $db->Record['zdom']);
else
$descr = sprintf("%s.<A HREF=\"zones.php?zone=%d\">%s</A>",
$db->Record['rdom'], $db->Record['zid'], $db->Record['zdom']);
$bytes = explode(".", $db->Record['rdata']);
$hosts[$bytes[3]][] = $descr;
}
$db->prepare("SELECT zones.domain AS zdom, zones.id AS zid, records.data AS rdata,
CONCAT(?, records.domain) AS rdom
FROM zones, records
WHERE zones.id = records.zone AND records.type = 'PTR' AND zones.domain = ?");
$db->execute($prefix.".",$subnet);
while ($db->next_record()) {
$descr = sprintf("%s<BR> (explicit PTR in <A HREF=\"zones.php?zone=%d\">%s</A>)",
$db->Record['rdata'], $db->Record['zid'], $db->Record['zdom']);
$bytes = explode(".", $db->Record['rdom']);
$hosts[$bytes[3]][] = $descr;
}
$firstfree = 256;
$result = "<TABLE><TR align=left><TH>Host</TH><TH>Hostname</TH></TR>\n";
for ($i=1; $i<255; $i++) {
if (@$hosts[$i]) {
if ($firstfree < $i) {
$lastfree = $i - 1;
if (($lastfree - $firstfree) >= 1)
$result .= "<TR><TD bgcolor=\"#669966\">$firstfree .. $lastfree</TD><TD background=\"../images/BG-shade-green.gif\">Not used</TD></TR>\n";
else
$result .= "<TR><TD bgcolor=\"#669966\">$firstfree</TD><TD background=\"../images/BG-shade-green.gif\">Not used</TD></TR>\n";
$firstfree = 256;
}
$result .= "<TR><TD bgcolor=\"#ff9933\">$i</TD><TD background=\"../images/BG-shade-orng.gif\">"
.join("<BR>\n\t",$hosts[$i])."</TD></TR>\n";
} else {
if ($firstfree > $i)
$firstfree = $i;
}
}
if ($firstfree < $i) {
$lastfree = $i - 1;
if (($lastfree - $firstfree) > 1)
$result .= "<TR><TD bgcolor=\"#669966\">$firstfree .. $lastfree</TD><TD background=\"../images/BG-shade-green.gif\">Not used</TD></TR>\n";
else
$result .= "<TR><TD bgcolor=\"#ff9933\">$firstfree</TD><TD background=\"../images/BG-shade-orng.gif\">Not used</TD></TR>\n";
}
$result .= "</TABLE>\n";
return $result;
}
#
# MAIN
#
$db = new DB_probind;
get_input();
$zid = false;
if ($subnet = @$INPUT_VARS['subnet']) {
$db->prepare("SELECT id FROM zones WHERE domain = ?");
$db->execute($subnet);
if ($db->next_record()) $zid = $db->Record[0];
else echo "$subnet not found.";
}
if ($zid) {
print "IP number usage in the <A HREF=\"zones.php?zone=$zid\">$subnet</A> subnet<P>\n<UL>\n";
print subnet_view($subnet);
print "</UL>\n";
} else {
print "Select a subnet to view<P>\n";
print "<FORM action=\"ip-ranges.php\" method=\"post\">\n";
print subnet_menu();
print "<INPUT type=\"submit\" value=\"View\">\n";
print "</FORM>\n";
}
?>
</BODY>
</HTML>