%
'Global Variables
Dim IPType, strTempString, NetworkID
Function GetMaskEndPosition(strmask)
Dim tmpmask, x
strmask = strmask & "."
tmpmask = Split(strmask, ".")
For x = 0 To UBound(tmpmask) - 1
Select Case tmpmask(x)
Case "255"
GetMaskEndPosition = x + 1
iMaskEndPosition = x + 1
Case Else
Exit For
End Select
Next
End Function
Public Sub LoadNetID(strNetID, strmask, ipRange)
Dim inet, ibroad, x, ipleft, iptemp, imaskend,count1
count1 = 0
strTempNetworkId = Left(strNetID,Len(strNetID)-3)
imaskend = GetMaskEndPosition(strmask)
strNetID = Mid(strNetID, 1, InStrRev(strNetID, "/", Len(strNetID)) - 1)
strNetID = strNetID & "."
iptemp = Split(strNetID, ".")
If ipRange = 0 Then ipRange = 256
For x = 0 To imaskend - 1
ipleft = ipleft & iptemp(x) & "."
Next
strTempString = "
Network | Broadcast |
"
If ipRange <> 256 Then
For x = 0 To 255 Step ipRange
count = count + 1
iptemp = Split(ipleft & "x", ".")
Select Case UBound(iptemp) + 1
Case 1
If strTempNetworkID = ipleft & x & ".0.0.0" then strTempString = strTempString & "" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & x & ".0.0.0" & spacelen & " | " & ipleft & x + (ipRange - 1) & ".255.255.255" & " | " & vbCrLF
Case 2
If strTempNetworkID = ipleft & x & ".0.0" then strTempString = strTempString & "
" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & x & ".0.0" & spacelen & " | " & ipleft & x + (ipRange - 1) & ".255.255" & " | " & vbCrLF
Case 3
If strTempNetworkID = ipleft & x & ".0" then strTempString = strTempString & "
" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & x & ".0" & spacelen & " | " & ipleft & x + (ipRange - 1) & ".255" & " | " & vbCrLF
Case 4
If strTempNetworkID = ipleft & x then strTempString = strTempString & "
" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & x & spacelen & " | " & ipleft & x + (ipRange - 1) & " | " & vbCrLF
End Select
strTempString = strTempString & "
"
Next
strTempString = strTempString & "
"
Else
iptemp = Split(ipleft & "x", ".")
Select Case UBound(iptemp) + 1
Case 1
If strTempNetworkID = ipleft & "0.0.0.0" then strTempString = strTempString & "" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & "0.0.0.0" & spacelen & " | " & ipleft & (ipRange - 1) & ".255.255.255" & " | " & vbCrLF
Case 2
If strTempNetworkID = ipleft & "0.0.0" then strTempString = strTempString & "
" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & "0.0.0" & spacelen & " | " & ipleft & (ipRange - 1) & ".255.255" & " | " & vbCrLF
Case 3
If strTempNetworkID = ipleft & "0.0" then strTempString = strTempString & "
" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & "0.0" & spacelen & " | " & ipleft & (ipRange - 1) & ".255" & " | " & vbCrLF
Case 4
If strTempNetworkID = ipleft & "0" then strTempString = strTempString & "
" Else If Count Mod 2 = 0 Then strTempString = strTempString & "
" Else strTempString = strTempString & "
"
strTempString = strTempString & "" & ipleft & "0" & spacelen & " | " & ipleft & (ipRange - 1) & " | " & vbCrLF
End Select
strTempString = strTempString & "
"
strTempString = strTempString & ""
End If
End Sub
Function GetPosHosts(strBinaryMask)
Dim tempdata, ix, itemp, ipclass, pos, BitCount
strBinaryMask = strBinaryMask & "."
tempdata = Split(strBinaryMask, ".")
For ix = 0 To UBound(tempdata) - 1
pos = 1
Do While pos <= Len(tempdata(ix)) + 1
If Mid(tempdata(ix), pos, 1) = "0" Then
BitCount = BitCount + 1
End If
pos = pos + 1
Loop
Next
'Takes 2 to the BitCount power that is not used by NetID - 2 (for netid and broadcast)
GetPosHosts = ((2 ^ BitCount) - 2)
End Function
Function GetPosNetworks(strmask)
Dim tempdata, ix, itemp, ipclass
strmask = strmask & "."
tempdata = Split(strmask, ".")
For ix = 0 To UBound(tempdata) - 1
Select Case tempdata(ix)
Case "128"
GetPosNetworks = 2 ^ 1
Case "192"
GetPosNetworks = 2 ^ 2
Case "224"
GetPosNetworks = 2 ^ 3
Case "240"
GetPosNetworks = 2 ^ 4
Case "248"
GetPosNetworks = 2 ^ 5
Case "252"
GetPosNetworks = 2 ^ 6
Case "254"
GetPosNetworks = 2 ^ 7
'Case Else
'GetPosNetworks = 1
End Select
Next
End Function
Function GetBits(strmask)
On Error Resume Next
Dim tempdata, ix, pos, itemp
strmask = strmask & "."
tempdata = Split(strmask, ".")
For ix = 0 To UBound(tempdata) - 1
Select Case tempdata(ix)
Case "255"
itemp = itemp + 8
Case "128"
itemp = itemp + 1
Case "192"
itemp = itemp + 2
Case "224"
itemp = itemp + 3
Case "240"
itemp = itemp + 4
Case "248"
itemp = itemp + 5
Case "252"
itemp = itemp + 6
Case "254"
itemp = itemp + 7
End Select
Next
GetBits = itemp
End Function
Function GetRange(strmask)
'uses the couchie method
Dim tempdata, ix, itemp, ipclass
strmask = strmask & "."
tempdata = Split(strmask, ".")
For ix = 0 To UBound(tempdata) - 1
Select Case tempdata(ix)
Case "128"
iRange = 256 - CInt(tempdata(ix))
Exit For
Case "192"
iRange = 256 - CInt(tempdata(ix))
Exit For
Case "224"
iRange = 256 - CInt(tempdata(ix))
Exit For
Case "240"
iRange = 256 - CInt(tempdata(ix))
Exit For
Case "248"
iRange = 256 - CInt(tempdata(ix))
Exit For
Case "252"
iRange = 256 - CInt(tempdata(ix))
Exit For
Case "254"
iRange = 256 - CInt(tempdata(ix))
Exit For
Case Else
iRange = 256
End Select
Next
GetRange = iRange
End Function
Function GetIPClass(strip)
On Error Resume Next
Dim tempip, x
strip = strip & "."
tempip = Split(strip, ".")
If tempip(0) => 0 And tempip(0) <= 127 Then
GetIPClass = "A"
If tempip(0) = 10 Then
IPType = "Reserved"
Exit Function
ElseIf tempip(0) = 127 Then
IPType = "Loopback"
GetIPClass = "Loopback"
Exit Function
End If
IPType = "Public"
End If
If tempip(0) => 128 And tempip(0) <= 191 Then
GetIPClass = "B"
If tempip(0) = 172 Then
If tempip(1) => 16 And tempip(1) <= 31 Then
IPType = "Reserved"
End If
Exit Function
End If
IPType = "Public"
End If
If tempip(0) => 192 And tempip(0) <= 223 Then
GetIPClass = "C"
If tempip(0) = 192 And tempip(1) = 168 Then
IPType = "Reserved"
Exit Function
End If
IPType = "Public"
End If
If tempip(0) => 224 And tempip(0) <= 239 Then
GetIPClass = "D"
IPType = "Multicast(RFC 1112)"
End If
If tempip(0) => 240 And tempip(0) <= 255 Then
GetIPClass = "E"
IPType = "Experemential"
End If
End Function
Function ConvertBinToIP(strBin)
On Error Resume Next
Dim pos, binarray, tempnetid, ix, x, y, z
strBin = strBin & "."
binarray = Split(strBin, ".")
For ix = 0 To UBound(binarray) - 1
x = 0
For y = 7 To 0 Step -1
If Mid(StrReverse(binarray(ix)), y + 1, 1) = "1" Then
x = x + BA(y)
Else
x = x
End If
Next
z = z & CStr(x) & "."
Next
ConvertBinToIP = Left(z, Len(z) - 1)
End Function
Function GetBinNetID(strip, StrSubnetMask)
On Error Resume Next
Dim pos, tempnetid, x, y, z
pos = 1
Do While pos <> Len(strip) + 1
If Mid(strip, pos, 1) <> "." Then
x = Mid(strip, pos, 1)
y = Mid(StrSubnetMask, pos, 1)
z = (CInt(x) * CInt(y))
tempnetid = tempnetid & z
Else
tempnetid = tempnetid & "."
End If
pos = pos + 1
Loop
GetBinNetID = tempnetid
End Function
Function ConvertBin(iValue)
On Error Resume Next
Dim C 'As Integer
Dim TempValue 'As Integer
Dim tempdata 'As String
If iValue = Null Then ConvertBin = "00000000": Exit Function
TempValue = 0
For C = 7 To 0 Step -1
If TempValue + BA(C) <= iValue Then
tempdata = tempdata & "1"
TempValue = TempValue + BA(C)
Else
tempdata = tempdata & "0"
End If
Next
ConvertBin = tempdata
End Function
'Setup Defaults
Dim BA(7), C
BA(0) = 1
For C = 1 To UBound(BA)
BA(C) = 2 ^ C
Next
'*****Begin Handling what has been passed******
'Declare Variables
Dim aryIPAddress, aryNetMask, IPAddress, NetMask, BinIPAddress, BinNetMask, BinNetworkID
Dim IPAddressClass, AddressType, GoodIPforHost, NumSubnets, Range, Hosts
'Get Base Information from Form1
IPAddress = Request.Querystring("IP")
NetMask = Request.QueryString("Mask")
aryIPAddress = Split(IPAddress,".")
aryNetMask = Split(NetMask,".")
'Convert IP and Mask to Binary
For x = 0 To 3
BinIPAddress = BinIPAddress & "." & ConvertBin(CInt(aryIPAddress(x)))
BinNetMask = BinNetMask & "." & ConvertBin(CInt(aryNetMask(x)))
Next
BinIPAddress = Mid(BinIPAddress,2)
BinNetMask = Mid(BinNetMask,2)
'Get Network Number(Bin)
BinNetworkID = GetBinNetID(BinIPAddress, BinNetMask)
'Get Network Number
NetworkID = ConvertBinToIP(BinNetworkID)
'Get Network Type and Class
IPAddressClass = GetIPClass(NetworkID)
AddressType = IPType
'Get the range
Range = GetRange(NetMask)
If Range = 256 Then Range = 1
'GetShortHand Mask notation
NetworkID = Left(NetworkID,Len(NetworkID)-1) & "/" & GetBits(NetMask)
'Get Number of subnets
NumSubnets = GetPosNetworks(NetMask)
'Get the number of available hosts per subnet
Hosts = GetPosHosts(BinNetMask)
If Range = 1 then temp = 256 else temp = Range
LoadNetID NetworkID, Left(NetMask,Len(NetMask)-3), temp
%>
New Page 3
|
IP
Address Calculator |
|
|
|
|
|
|
|
IP Information |
|
<%=strTempString%> |
|
IP Address |
<%=IPAddress%> |
|
Subnet Mask |
<%=NetMask%>
|
|
Network ID |
<%=Left(NetworkID,Len(NetworkID)-1) & "/" & GetBits(NetMask) %> |
|
|
|
|
Binary Information |
|
IP Address |
<%=BinIPAddress%> |
|
Subnet Mask |
<%=Left(BinNetMask,Len(BinNetMask)-1)%> |
|
Network |
<%=Left(BinNetworkID,Len(BinNetworkID)-1)%> |
|
|
|
|
Network Information |
|
IP Address Class |
<%=IPAddressClass%> |
|
Address Type |
<%=AddressType%> |
|
|
|
|
Subnet Information |
|
Number of Subnets |
<%If NumSubnets = "" Then Response.Write "0" Else Response.Write NumSubnets%> |
|
Number of Hosts |
<%=Hosts%> |
|
Range |
<%=Range%>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|