这篇文章主要介绍了php与js中检测ip地址及域名的函数,方便大家在写程序中检测ip与域名,需要的朋友可以参考下
PHP IP地址格式检测函数
复制代码 代码如下:
function checkIp($ip){
$ip = str_replace(" ", "", $ip);
$ip = strtolower($ip);
$ip= str_replace("http://", "", $ip);
$ip= str_replace("https://", "", $ip);
if(preg_match('/[A-Za-z_-]/',$ip)){
if(preg_match('/^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|(io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp)|(co)|(me)|(mx)|(ca)|(ag)|(com\.co)|(net\.co)|(nom\.co)|(com\.ag)|(net\.ag)|(fr)|(org\.ag)|(am)|(asia)|(at)|(be)|(bz)|(com\.bz)|(net\.bz)|(net\.br)|(com\.br)|(de)|(es)|(com\.es)|(nom\.es)|(org\.es)|(fm)|(gs)|(co\.in)|(firm\.in)|(gen\.in)|(ind\.in)|(net\.in)|(org\.in)|(jobs)|(ms)|(com\.mx)|(nl)|(nu)|(co\.nz)|(net\.nz)|(org\.nz)|(tc)|(tk)|(org\.tw)|(idv\.tw)|(co\.uk)|(vg)|(ad)|(ae)|(af)|(ai)|(al)|(an)|(ao)|(aq)|(ar)|(as)|(au)|(aw)|(az)|(ba)|(bb)|(bd)|(bf)|(bg)|(bh)|(bi)|(bj)|(bm)|(bn)|(bo)|(br)|(bs)|(bt)|(bv)|(bw)|(by)|(cd)|(cf)|(cg)|(ch)|(ci)|(ck)|(cl)|(cm)|(cr)|(cu)|(cv)|(cx)|(cy)|(cz)|(dj)|(dk)|(dm)|(do)|(dz)|(ec)|(ee)|(eg)|(er)|(et)|(fi)|(fj)|(fk)|(fo)|(ga)|(gd)|(ge)|(gf)|(gg)|(gh)|(gi)|(gl)|(gm)|(gn)|(gp)|(gq)|(gr)|(gt)|(gu)|(gw)|(gy)|(hm)|(hn)|(hr)|(ht)|(hu)|(id)|(ie)|(il)|(im)|(iq)|(ir)|(is)|(je)|(jm)|(jo)|(ke)|(kg)|(kh)|(ki)|(km)|(kn)|(kr)|(kw)|(ky)|(kz)|(lb)|(lc)|(li)|(lk)|(lr)|(ls)|(lt)|(lu)|(lv)|(ly)|(ma)|(mc)|(md)|(mg)|(mh)|(mk)|(ml)|(mm)|(mn)|(mo)|(mp)|(mq)|(mr)|(mt)|(mu)|(mv)|(mw)|(my)|(mz)|(na)|(nc)|(ne)|(nf)|(ng)|(ni)|(no)|(np)|(nr)|(nz)|(om)|(pa)|(pe)|(pf)|(pg)|(ph)|(pk)|(pl)|(pm)|(pn)|(pr)|(ps)|(pt)|(pw)|(py)|(qa)|(re)|(ro)|(ru)|(rw)|(sa)|(sb)|(sc)|(sd)|(se)|(sg)|(si)|(sk)|(sl)|(sm)|(sn)|(sr)|(st)|(sv)|(sy)|(sz)|(td)|(tf)|(tg)|(th)|(tj)|(tl)|(tn)|(to)|(tr)|(tt)|(tz)|(ua)|(ug)|(uk)|(uy)|(uz)|(va)|(vc)|(ve)|(vi)|(vn)|(vu)|(wf)|(ye)|(yt)|(yu)|(za)|(zm)|(zw))$/i',$ip)){
return true;
}else{
return false;
}
}else{
$ipArray = explode(".", $ip);
$j = count($ipArray);
if($j!=4)
{
return false;
}
for( $i=0;$i
if(strlen($ipArray[$i])==0 || $ipArray[$i]>255){
return false;
}
}
return true;
}
}
JS代码:
复制代码 代码如下:
function checkIP(){
var ipArray,ip,j;
ip = document.ipform.ip.value;
if (ip.indexOf(" ")>=0){
ip = ip.replace(/ /g,"");
document.ipform.ip.value = ip;
}
if (ip.toLowerCase().indexOf("http://")==0){
ip = ip.slice(7);
document.ipform.ip.value = ip;
}
if (ip.toLowerCase().indexOf("https://")==0){
ip = ip.slice(8);
document.ipform.ip.value = ip;
}
if (ip.slice(ip.length-1)=="/"){
ip = ip.slice(0,ip.length-1);
document.ipform.ip.value = ip;
}
if(/[A-Za-z_-]/.test(ip)){
if(!/^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|(io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp)|(co)|(me)|(mx)|(ca)|(ag)|(com\.co)|(net\.co)|(nom\.co)|(com\.ag)|(net\.ag)|(fr)|(org\.ag)|(am)|(asia)|(at)|(be)|(bz)|(com\.bz)|(net\.bz)|(net\.br)|(com\.br)|(de)|(es)|(com\.es)|(nom\.es)|(org\.es)|(fm)|(gs)|(co\.in)|(firm\.in)|(gen\.in)|(ind\.in)|(net\.in)|(org\.in)|(jobs)|(ms)|(com\.mx)|(nl)|(nu)|(co\.nz)|(net\.nz)|(org\.nz)|(tc)|(tk)|(org\.tw)|(idv\.tw)|(co\.uk)|(vg)|(ad)|(ae)|(af)|(ai)|(al)|(an)|(ao)|(aq)|(ar)|(as)|(au)|(aw)|(az)|(ba)|(bb)|(bd)|(bf)|(bg)|(bh)|(bi)|(bj)|(bm)|(bn)|(bo)|(br)|(bs)|(bt)|(bv)|(bw)|(by)|(cd)|(cf)|(cg)|(ch)|(ci)|(ck)|(cl)|(cm)|(cr)|(cu)|(cv)|(cx)|(cy)|(cz)|(dj)|(dk)|(dm)|(do)|(dz)|(ec)|(ee)|(eg)|(er)|(et)|(fi)|(fj)|(fk)|(fo)|(ga)|(gd)|(ge)|(gf)|(gg)|(gh)|(gi)|(gl)|(gm)|(gn)|(gp)|(gq)|(gr)|(gt)|(gu)|(gw)|(gy)|(hm)|(hn)|(hr)|(ht)|(hu)|(id)|(ie)|(il)|(im)|(iq)|(ir)|(is)|(je)|(jm)|(jo)|(ke)|(kg)|(kh)|(ki)|(km)|(kn)|(kr)|(kw)|(ky)|(kz)|(lb)|(lc)|(li)|(lk)|(lr)|(ls)|(lt)|(lu)|(lv)|(ly)|(ma)|(mc)|(md)|(mg)|(mh)|(mk)|(ml)|(mm)|(mn)|(mo)|(mp)|(mq)|(mr)|(mt)|(mu)|(mv)|(mw)|(my)|(mz)|(na)|(nc)|(ne)|(nf)|(ng)|(ni)|(no)|(np)|(nr)|(nz)|(om)|(pa)|(pe)|(pf)|(pg)|(ph)|(pk)|(pl)|(pm)|(pn)|(pr)|(ps)|(pt)|(pw)|(py)|(qa)|(re)|(ro)|(ru)|(rw)|(sa)|(sb)|(sc)|(sd)|(se)|(sg)|(si)|(sk)|(sl)|(sm)|(sn)|(sr)|(st)|(sv)|(sy)|(sz)|(td)|(tf)|(tg)|(th)|(tj)|(tl)|(tn)|(to)|(tr)|(tt)|(tz)|(ua)|(ug)|(uk)|(uy)|(uz)|(va)|(vc)|(ve)|(vi)|(vn)|(vu)|(wf)|(ye)|(yt)|(yu)|(za)|(zm)|(zw))$/i.test(ip)){
alert("不是正确的域名");
document.ipform.ip.focus();
return false;
}
}
else{
ipArray = ip.split(".");
j = ipArray.length
if(j!=4)
{
alert("不是正确的IP");
document.ipform.ip.focus();
return false;
}
for(var i=0;i{
if(ipArray[i].length==0 || ipArray[i]>255)
{
alert("不是正确的IP");
document.ipform.ip.focus();
return false;
}
}
}
}
注意:上面的函数单行很长,,大家复制后注意不要分行了。

cmd查看局域网所有ip的方法:1、按“Win+R”快捷键打开“运行”窗口;2、在“运行”窗口中输入“CMD”后,按回车键;3、在打开的“命令提示符”界面中,输入命令“arp -a”并按回车键;4、从返回结果就可以看到本地局域网中的所有与本机通信的计算机IP地址。

主机的域名和主机的ip地址两者之间的关系是:一个IP地址对应多个域名。IP地址用数字化形式来对计算机网络中的主机进行网络标识,域名用字符化形式来对计算机网络中的主机进行网络标识。在Internet中,一个域名之内能够对应一个IP地址,但是一个IP地址可以被多个域名所对应。

随着网络的快速发展,IP地址成为了网络通信中不可或缺的一环。在进行网络安全监测、流量管理、电商广告定向投放等方面,IP地址的信息非常重要。因此,为了方便用户查询IP地址/域名信息,许多网站提供了IP地址查询功能。本篇文章将介绍如何用PHP实现IP地址查询功能,供读者参考。一、何为IP地址?IP地址(InternetProtocolAddress)即网络协

每一台主机都有唯一的地址标识称为“IP地址”。IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络和每一台主机分配一个唯一的逻辑地址,以此来屏蔽物理地址的差异。由于有这种唯一的地址,才保证了用户在连网的计算机上操作时,能够高效而且方便地从千千万万台计算机中选出自己所需的对象来。

ip地址是由32或128位二进制数组成。IP地址是IP协议提供的一种统一的地址格式,IP地址分两种:1、ipv4地址,由32位二进制数组成,用点分十进制表示,每八位划分,也就是四个0~255的十进制数;2、ipv6地址,由128位二进制数组成,用点分十六进制表示,每八位划分,也就是十六个0x00~0xff的十六进制数。

一、前言环境:jdk1.8+idea2019.3+Windows10二、摘要项目开发中,在日常处理操作日志时,基本都会通过aop切面来实现用户操作日志的记录,但涉及到记录操作日志,想必肯定会有一项是基本都会参考记录的,那就是操作人的客户端ip地址,日后查"脏"也方便。那么问题来了。具体怎么获取客户端的ip地址啊?哈哈哈,这就是我这期的教学内容,若是有的小伙伴知道怎么获取,那么我要表扬你,但是实现思路是否与我有同异?所以你也可以尝试看下bug菌是如何实现的吧。接下来,我就开始教

ip地址后面的“/24”表示掩码位是24位的。IP地址是四个十进制数组成的,相当于32位二进制;而ip地址后面斜杠加具体数字是一种用CIDR形式表示的一个网段,或者说子网。ip地址后“/24”指32位二进制的前24位用"1"表示,后面8位用0表示,即“11111111 11111111 11111111 000000”;将其转化为十进制,就是“255.255.255.0”。

ip地址和所在地不一样的原因:1、运营商IP分配错误会导致IP真实所在地与腾讯IP数据库匹配到的IP所在地不同;2、使用代理服务器导致的;3、非官方版本导致的,请检查所使用的软件版本,是否为官方软件,只有官方版本才会应用更加精确的IP数据库。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
