利用HTML+JAVASCRIPT编写的判断IP地址合法性,并将其合法IP地址分类
2008-12-11 13:46
483 查看
index.html
<HTML>
<HEAD>
</HEAD>
<Frameset Rows="50%,50%">
<frame name=top1 src="top.html">
<frame name=bottom src="bottom.html">
</Frameset>
</HTML>
top.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test</title>
</head>
<body bgcolor="#F0F7FF" text="#FF0000">
<p align="center"><b>
<script language=javascript>
todayDate=new Date();
date=todayDate.getDate();
month=todayDate.getMonth() +1;
year=todayDate.getYear();
document.write("Today is")
document.write("<br>")
if(navigator.appName=="Netscape")
{
document.write(1900+year);
document.write("/");
document.write(month);
document.write("/");
document.write(date);
document.write(" ");
document.write("<br>")
}
if(navigator.appVersion.indexOf("MSIE") != -1)
{
document.write(year);
document.write("/");
document.write(month);
document.write("/");
document.write(date);
document.write(" ");
document.write("<br>")
}
if (todayDate.getDay() == 5) document.write("Friday")
if (todayDate.getDay() == 6) document.write("saturday")
if (todayDate.getDay() == 0) document.write("sunday")
if (todayDate.getDay() == 1) document.write("monday")
if (todayDate.getDay() == 2) document.write("tuesday")
if (todayDate.getDay() == 3) document.write("wednesday")
if (todayDate.getDay() == 4) document.write("thursday")
<br>
function checkIP2()
{
var ip=document.all.ip.value;
var exp=/^(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])$/;
var reg=ip.match(exp);
var ErrMsg="You enter the IP address is illegal, it is the right format/nIP:xxx.xxx.xxx.xxx(xxxIn the range of between0-255)"
var Msg="You enter the IP address is legitimate!"
if(reg==null)
{
alert(ErrMsg);
return false;
}
else
{
alert(reg);
showresult();
}
}
function showresult()
{
parent.bottom.window.location.reload();
}
</script>
<form name="form1" >
<h2 align="center">Please input IP Address:</h2><br>
<INPUT TYPE="text" NAME="ip" id="ip">
<br><br>
<INPUT TYPE="button" value="Submit" onclick="checkIP2()">
<input type="reset" value="reset">
</form>
</b></p>
</body>
</html>
bottom.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test3</title>
</head>
<body onload=checkIP()>
<script language=javascript>
function checkIP()
{
var IP=parent.top1.document.forms[0].ip.value;
var lastip;
lastip=IP.split("."); //Use. Ip to separate
if(parseInt(lastip[0])<=126) //First determine the scope of the ip address
{
if(parseInt(lastip[0])==10)
{
document.write(IP);
document.write("<h1>This is private Address!</h1>");
}
else
{
document.write(IP);
document.write("<h1>This is belong to the A class of address!</h1>");
}
}
else
{
if(parseInt(lastip[0])==127)
{
document.write(IP);
document.write("<h1>This is the address of the LookBack!</h1>");
}
else
{
if(parseInt(lastip[0])<=191)
{
document.write(IP);
document.write("<h1>Belong to the B category of address!</h1>");
}
else
{
if(parseInt(lastip[0])<=223)
{
if(parseInt(lastip[0])==192&&parseInt(lastip[1]==168))
{
document.write(IP);
document.write("<h1>This is private Address!</h1>");
}
else
{
document.write(IP);
document.write("<h1>Belong to the C category of address!</h1>");
}
}
else
{
if(parseInt(lastip[0])<=239)
{
document.write(IP);
document.write("<h1>This is belong to the D class of Address!</h1>");
}
else
{
if(parseInt(lastip[0])<=255)
{
document.write(IP);
document.write("<h1>This is belong to the E class of Address!</h1>");
}
else
{
document.write("Did not enter the ip address!");
}
}
}
}
}
}
}
</script>
</body>
</html>
这个是在一个页面中设计两个框架,上面的框架设计一个表单文本框,然后判断输入IP地址的合法性;如果是合法的IP地址就将其传值给下面的bottom框架进行判断。看是哪一类IP地址。
<HTML>
<HEAD>
</HEAD>
<Frameset Rows="50%,50%">
<frame name=top1 src="top.html">
<frame name=bottom src="bottom.html">
</Frameset>
</HTML>
top.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test</title>
</head>
<body bgcolor="#F0F7FF" text="#FF0000">
<p align="center"><b>
<script language=javascript>
todayDate=new Date();
date=todayDate.getDate();
month=todayDate.getMonth() +1;
year=todayDate.getYear();
document.write("Today is")
document.write("<br>")
if(navigator.appName=="Netscape")
{
document.write(1900+year);
document.write("/");
document.write(month);
document.write("/");
document.write(date);
document.write(" ");
document.write("<br>")
}
if(navigator.appVersion.indexOf("MSIE") != -1)
{
document.write(year);
document.write("/");
document.write(month);
document.write("/");
document.write(date);
document.write(" ");
document.write("<br>")
}
if (todayDate.getDay() == 5) document.write("Friday")
if (todayDate.getDay() == 6) document.write("saturday")
if (todayDate.getDay() == 0) document.write("sunday")
if (todayDate.getDay() == 1) document.write("monday")
if (todayDate.getDay() == 2) document.write("tuesday")
if (todayDate.getDay() == 3) document.write("wednesday")
if (todayDate.getDay() == 4) document.write("thursday")
<br>
function checkIP2()
{
var ip=document.all.ip.value;
var exp=/^(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])$/;
var reg=ip.match(exp);
var ErrMsg="You enter the IP address is illegal, it is the right format/nIP:xxx.xxx.xxx.xxx(xxxIn the range of between0-255)"
var Msg="You enter the IP address is legitimate!"
if(reg==null)
{
alert(ErrMsg);
return false;
}
else
{
alert(reg);
showresult();
}
}
function showresult()
{
parent.bottom.window.location.reload();
}
</script>
<form name="form1" >
<h2 align="center">Please input IP Address:</h2><br>
<INPUT TYPE="text" NAME="ip" id="ip">
<br><br>
<INPUT TYPE="button" value="Submit" onclick="checkIP2()">
<input type="reset" value="reset">
</form>
</b></p>
</body>
</html>
bottom.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test3</title>
</head>
<body onload=checkIP()>
<script language=javascript>
function checkIP()
{
var IP=parent.top1.document.forms[0].ip.value;
var lastip;
lastip=IP.split("."); //Use. Ip to separate
if(parseInt(lastip[0])<=126) //First determine the scope of the ip address
{
if(parseInt(lastip[0])==10)
{
document.write(IP);
document.write("<h1>This is private Address!</h1>");
}
else
{
document.write(IP);
document.write("<h1>This is belong to the A class of address!</h1>");
}
}
else
{
if(parseInt(lastip[0])==127)
{
document.write(IP);
document.write("<h1>This is the address of the LookBack!</h1>");
}
else
{
if(parseInt(lastip[0])<=191)
{
document.write(IP);
document.write("<h1>Belong to the B category of address!</h1>");
}
else
{
if(parseInt(lastip[0])<=223)
{
if(parseInt(lastip[0])==192&&parseInt(lastip[1]==168))
{
document.write(IP);
document.write("<h1>This is private Address!</h1>");
}
else
{
document.write(IP);
document.write("<h1>Belong to the C category of address!</h1>");
}
}
else
{
if(parseInt(lastip[0])<=239)
{
document.write(IP);
document.write("<h1>This is belong to the D class of Address!</h1>");
}
else
{
if(parseInt(lastip[0])<=255)
{
document.write(IP);
document.write("<h1>This is belong to the E class of Address!</h1>");
}
else
{
document.write("Did not enter the ip address!");
}
}
}
}
}
}
}
</script>
</body>
</html>
这个是在一个页面中设计两个框架,上面的框架设计一个表单文本框,然后判断输入IP地址的合法性;如果是合法的IP地址就将其传值给下面的bottom框架进行判断。看是哪一类IP地址。
相关文章推荐
- 利用javascript窗口框架做的判断ip地址合法性并将其分类
- Linux学习之道:编写一个判断IP地址合法性的bash脚本
- 编写一个判断IP地址合法性的bash脚本
- 利用javascript验证邮箱地址是否合法
- 【用jQuery来判断浏览器的类型】及【javascript获取用户ip地址】
- 判断一个字符串的ip是否是IP合法的ip地址
- IP地址分类/IP地址10开头和172开头和192开头的区别/判断是否同一网段(A、B、C三类地址)
- 编写正则表达式,判断给定的是否是一个合法的IP地址。
- 如何利用Python判断一个字符串是合法ip
- 如何利用js正则表达式判断ip地址的合法性?(正则表达式太厉害了)
- JavaScript网站设计实践(四)编写about.html页面,利用JavaScript和DOM,选择性的显示和隐藏DIV元素
- [C#]判断是否是合法的IP4,IP6地址
- 编写正则表达式,判断给定的是否是一个合法的IP地址。
- Java:判断IP4地址合法性
- javascript正则表达式判断邮箱地址是否合法
- 编写正则表达式,判断给定的是否是一个合法的IP地址。
- IP地址的合法性验证,以及两IP地址大小的比较
- JavaScript判断E-mail地址是否合法
- 判断IP地址,MAC地址合法性-C语言
- 【用jQuery来判断浏览器的类型】及【javascript获取用户ip地址】