MsgBox % CIDRtoIPv4Range( "23.19.0.0/16" ) ; returns 23.19.0.0-23.19.255.255
MsgBox % CIDRfmIPv4Range( "23.19.0.0-23.19.255.255" ) ; returns 23.19.0.0/16
MsgBox % IPv4toLong( "23.19.0.0" ) ; returns 387121152
MsgBox % IPv4fmLong( 387121152 ) ; returns 23.19.0.0
VarLow := IPv4toLong( "23.19.0.0" )
VarHigh := IPv4toLong( "23.19.255.255" )
Var := IPv4toLong( "23.19.128.80" )
If Var between %VarLow% and %VarHigh%
MsgBox %Var% is between %VarLow% and %VarHigh%.
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=1238
CIDRfmIPv4Range( IPV4Range ) { ; SKAN | 01-Jan-2014 | goo.gl/JI0kml
Static IP1,IP2,IP3,IP4,IP5,IP6,IP7,IP8
StringSplit, IP, IPV4Range, .-, %A_Space%`t
IPDiff := 1 + ( IP8 | ( IP7<<8 ) | ( IP6<<16 ) | ( IP5<<24 ) )
- ( IP4 | ( IP3<<8 ) | ( IP2<<16 ) | ( IP1<<24 ) )
Return IP1 "." IP2 "." IP3 "." IP4 "/" Round( 32 - ( LN(IPDiff)/LN(2) ) )
}
CIDRtoIPv4Range( CIDR ) { ; SKAN | 01-Jan-2014 | goo.gl/JI0kml
Static IPF1,IPF2,IPF3,IPF4,IPT1,IPT2,IPT3,IPT4
StringSplit, IPF, CIDR, ./
LI := ( N := 0xFFFFFFFF >> IPF5 ) | ( IPF4 | ( IPF3<<8 ) | ( IPF2<<16 ) | ( IPF1<<24 ) )
IPT1 := LI>>24, IPT2 := LI>>16 & 255, IPT3 := LI>>8 & 255, IPT4 := LI & 255
Return IPF1 "." IPF2 "." IPF3 "." IPF4 "-" IPT1 "." IPT2 "." IPT3 "." IPT4
, ErrorLevel := 1 + N
}
IPv4fmLong( LI, BigEndian=0 ) { ; SKAN | 01-Jan-2014 | goo.gl/JI0kml
Static Octet1,Octet2,Octet3,Octet4
Octet1 := LI>>24, Octet2 := LI>>16 & 255, Octet3 := LI>>8 & 255, Octet4 := LI & 255
Return BigEndian=0 ? Octet1 "." Octet2 "." Octet3 "." Octet4
: Octet4 "." Octet3 "." Octet2 "." Octet1
}
IPv4toLong( IP, BigEndian=0 ) { ; SKAN | 01-Jan-2014 | goo.gl/JI0kml
Static Octet1,Octet2,Octet3,Octet4
StringSplit, Octet, IP, .
Return BigEndian=0 ? ( Octet4 | ( Octet3<<8 ) | ( Octet2<<16 ) | ( Octet1<<24 ) )
: ( Octet1 | ( Octet2<<8 ) | ( Octet3<<16 ) | ( Octet4<<24 ) )
}
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)