-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIP地址转换.html
156 lines (146 loc) · 4.74 KB
/
IP地址转换.html
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<!-- saved from url=(0042)http://redmark.site/tools/ip_converter.htm -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>IP地址转换</title>
</head>
<body>
<div class="xnews-con">
<h1>IP地址转换</h1>
<div class="container">
<div class="main">
<div class="news-right">
<table style="WIDTH: 100%">
<tbody>
<tr>
<td width="100%" valign="top">
<div id="cont_right_calc">
<script type="text/javascript">
function ipcon(){
var ipv = document.getElementById("inp1").value;
if(ipv == ''){
document.getElementById("error1").innerHTML = '无效的IP地址';
return false;
}else{
var ar = ipv.split(".");
var decm = parseInt(ar[0])*256*256*256+parseInt(ar[1])*256*256+parseInt(ar[2])*256+parseInt(ar[3]);
var hex = parseInt(decm).toString(16).toUpperCase();
var binary = parseInt(decm).toString(2).toUpperCase();
//decm = parseInt(decm)+1;
document.getElementById("res").innerHTML = '十六进制 = '+hex+'<br> 十进制 = '+decm+"<br> 二进制 = "+binary;
}
}
function hex(){
var ipv = document.getElementById("inp2").value;
ipv = ipv.toUpperCase();
if(ishex(ipv)){
ipv = parseInt(ipv,16)
var b = new Array();
b[0] =0;
b[1] =0;
b[2] =0;
b[3] =0;
var c = 16777216.0;
for (var i = 0; i < 4; i++) {
var k = parseInt(ipv / c);
ipv -= c * k;
b[i]= k;
c = c/256.0;
}
d=b[0]+'.'+b[1]+'.'+b[2]+'.'+b[3];
document.getElementById("res2").innerHTML = "IP = "+d;
}else{
document.getElementById("error2").innerHTML = '无效的十六进制值';
return false;
}
}
function decimal(){
var ipv = parseInt(document.getElementById("inp3").value);
if ((/[^0-9]/g.test(ipv)) ==false|| ipv != "") {
var b = new Array();
b[0] =0;
b[1] =0;
b[2] =0;
b[3] =0;
var c = 16777216.0;
for (var i = 0; i < 4; i++) {
var k = parseInt(ipv / c);
ipv -= c * k;
b[i]= k;
c = c/256.0;
}
d=b[0]+'.'+b[1]+'.'+b[2]+'.'+b[3];
document.getElementById("res3").innerHTML = "IP = "+d;
}else{
document.getElementById("error3").innerHTML = '无效的十进制值';
return false;
}
}
function ishex(num){
var validChar='0123456789ABCDEF';
var flag=true;
var x=num.toUpperCase();
for(idx=0;idx<x.length;idx++){
if(validChar.indexOf(x.charAt(idx))<0){
return false;
}
}
return true;
}
</script>
<table width="100%" height="521">
<tbody>
<tr>
<td>
<div id="input">
<table style="MARGIN: 0px; WIDTH: 100%">
<tbody>
<tr>
<td id="title" colspan="2" valign="top" bgcolor="#ECFFF5" align="center">
<h3>IP地址转换到十六进制,十进制,二进制地址</h3></td></tr>
<tr>
<td width="70" valign="top" bgcolor="#ECFFF5"><label>IP地址</label></td>
<td bgcolor="#ECFFF5"><input id="inp1" value="" type="text"> </td></tr>
<tr>
<td bgcolor="#ECFFF5" align="center"></td>
<td bgcolor="#ECFFF5"><button onclick="ipcon()" type="button">转换</button></td></tr>
<tr>
<td></td>
<td id="res" width="314"></td></tr></tbody></table><br>
<table style="MARGIN: 0px; WIDTH: 100%">
<tbody>
<tr>
<td id="title" colspan="2" valign="top" bgcolor="#E6F2FF" align="center">
<h3>十六进制转换为IP地址</h3></td></tr>
<tr>
<td width="70" valign="top" bgcolor="#E6F2FF">16进制</td>
<td bgcolor="#E6F2FF"><input id="inp2" type="text"> </td></tr>
<tr>
<td bgcolor="#E6F2FF" align="center">
</td>
<td bgcolor="#E6F2FF"><button onclick="hex()" type="button">转换</button></td></tr>
<tr>
<td></td>
<td id="res2"></td></tr></tbody></table><br>
<table style="MARGIN: 0px; WIDTH: 100%">
<tbody>
<tr>
<td id="title" colspan="2" valign="top" bgcolor="#FFE6E6" align="center">
<h3>十进制转成IP地址</h3>
</td></tr>
<tr>
<td width="70" valign="top" bgcolor="#FFE6E6">10进制</td>
<td bgcolor="#FFE6E6"><input id="inp3" type="text"> </td></tr>
<tr>
<td bgcolor="#FFE6E6" align="center"></td>
<td bgcolor="#FFE6E6"><button onclick="decimal()" type="button">转换</button></td></tr>
<tr>
<td></td>
<td id="res3"></td></tr></tbody></table></div></td></tr>
</tbody></table></div></td></tr>
</tbody></table>
</div>
</div>
</div>
</div>
<!--评论开始-->
</body></html>