Implementation of IP Address segmentation calculation by ASP

Source: Internet
Author: User
Tags end return split
IP address |ip address <script language= "JScript" runat= "Server" >
function Ipdecode (EIP) {
var ip1,ip2,ip3,ip4;
IP1 = Movebyter (EIP & 0xff000000,3);
IP2 = Movebyter (EIP & 0x00ff0000,2);
IP3 = Movebyter (EIP & 0x0000ff00,1);
IP4 = EIP & 0x000000ff;
return IP1 + "." + Ip2 + "." + Ip3 + "." + Ip4;
}

function Movebytel (num,bytenum) {
Return num <<= (bytenum*8)
}
function Movebyter (num,bytenum) {
Return num >>>= (bytenum*8)
}
</script>

There is no bit operation in the VBS, so in a page with JS and VBS, and not good, if the VBS can also, but wordy some, and a little note, if in the VBS split ("202.102.29.6", "."), will get 202,102, 293 number, Not get the last 6, so you need to replace the IP with split ("202.102.29.6" & ".", ".")
I do with the VBS, because there is no bit operation, so do more trouble
<%
function Ip2int (IPSTR)
Dim Iptemp,max
Iptemp = Split (ipstr& ".", ".")
max = UBound (iptemp)
If Max <> 4 then
Exit function
End If
Dim a,b,i
A = "&h"
For i = 0 to 3
b = Hex (Iptemp (i))
If Len (b) = 1 Then
b = "0" &b
End If
A = A&b
Next
Ip2int = CLng (a)
End Function
function Int2ip (IP)
Dim iptemp,a,ipstr,i,length
iptemp = Hex (IP)
Length = 8-len (iptemp)
For i = 1 to length
Iptemp = "0" & Iptemp
Next
A = Left (iptemp,2)
A = "&h" & A
i = CInt (a)
A = CSTR (i)
Ipstr = A & "."
A = Mid (iptemp,3,2)
A = "&h" & A
i = CInt (a)
A = CSTR (i)
Ipstr = Ipstr & A & "."
A = Mid (iptemp,5,2)
A = "&h" & A
i = CInt (a)
A = CSTR (i)
Ipstr = Ipstr & A & "."
A = right (iptemp,2)
A = "&h" & A
i = CInt (a)
A = CSTR (i)
Ipstr = Ipstr & A
Int2ip = Ipstr
End Function
Dim testip,testint
testip= "202.102.29.6"
Testint = Ip2int (Testip)
Response.Write Testip & "'ll be encoded to <font color=red>" & Testint & "</font><br>"
Response.Write Testip & "'ll be dencoded to <font color=red>" & Int2ip (Testint) & "</font><br > "
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.