-
Notifications
You must be signed in to change notification settings - Fork 6
/
calculator.php
107 lines (95 loc) · 2.46 KB
/
calculator.php
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
<?php
if (isset($_REQUEST['address']))
{
$address = $_REQUEST['address'];
$len = $_REQUEST['prefixlen'];
require_once 'IPV6SubnetCalculator.php';
$calc = new IPV6SubnetCalculator();
if ($calc->testValidAddress($address))
{
$rangedata = $calc->getAddressRange($address, $len);
$ret = array(
"Abbreviated Address: " . $calc->abbreviateAddress($address) . "\n",
"Unabbreviated Address: " . $calc->unabbreviateAddress($address) . "\n",
"Prefix Length: " . $_REQUEST['prefixlen'] . "\n",
"Number of IPs: " . $calc->getInterfaceCount($len) . "\n",
"Start IP: " . $rangedata['start_address'] . "\n",
"End IP: " . $rangedata['end_address'] . "\n",
"Prefix Address: " . $rangedata['prefix_address'] . "\n",
);
} else {
$ret = array('That is not a valid IPv6 Address');
}
die(json_encode($ret));
}
?>
<html>
<head>
<title>IPv6 Subnet Calculator</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<style>
.calculator {
width: 650px;
height: 550px;
background-color: #cdcdcd;
}
.calculator .header {
background-color: lightsteelblue;
}
.calculator .inputs {
background-color: #ccc;
}
.ipv6-address {
width: 345px;
}
.results {
height: 400px;
background-color: white;
border: 1px dotted #000;
}
</style>
<script type='text/javascript'>
$(document).ready(function() {
// Set a default value
$('.prefix-length').val('64');
$('.check').click(function() {
$.ajax({
url: '<?php echo $_SERVER['SCRIPT_NAME']; ?>',
data: {
address: $('.ipv6-address').val(),
prefixlen: $('.prefix-length').val()
},
dataType: 'json',
success: function(data) {
$('.results-text').text('');
$.each(data, function(i, d) {
$('.results-text').append(d);
});
}
});
});
});
</script>
</head>
<body>
<div class='calculator'>
<div class='header'>IPv6 Subnet Calculator</div>
<div class='inputs'>
<h4>Enter an IPv6 Address and prefix length<h4>
<input type='text' name='address' class='ipv6-address'>
<select name='prefix' class='prefix-length'>
<?php
for ($i=8; $i <= 128; $i++)
{
echo "<option value='{$i}'>{$i}</option>";
}
?>
</select>
<button class='check'>Check</button>
</div>
<div class='results'>
<pre class='results-text'></pre>
</div>
</div>
</body>
</html>