Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -1,23 +1,15 @@
func$ can_cidr s$ .
n[] = number strsplit s$ "./"
if len n[] <> 5
return ""
.
n[] = number strtok s$ "./"
if len n[] <> 5 : return ""
for i to 4
if n[i] < 0 or n[i] > 255
return ""
.
if n[i] < 0 or n[i] > 255 : return ""
ad = ad * 256 + n[i]
.
if n[5] > 31 or n[5] < 1
return ""
.
if n[5] > 31 or n[5] < 1 : return ""
mask = bitnot (bitshift 1 (32 - n[5]) - 1)
ad = bitand ad mask
for i to 4
if r$ <> ""
r$ = "." & r$
.
if r$ <> "" : r$ = "." & r$
r$ = ad mod 256 & r$
ad = ad div 256
.

View file

@ -1,54 +1,99 @@
#lang "qb"
Const MAX_OCTET = 255
Const MIN_NETWORK = 1
Const MAX_NETWORK = 32
Const OCTET_BITS = 8
REM THE Binary OPS ONLY WORK On SIGNED 16-Bit NUMBERS
REM SO WE STORE THE IP ADDRESS As AN ARRAY OF FOUR OCTETS
Cls
Dim IP(3)
Do
REM Read DEMO Data
140 Read CI$
If CI$ = "" Then Exit Do 'Sleep: End
REM FIND /
SL = 0
For I = Len(CI$) To 1 Step -1
If Mid$(CI$,I,1) = "/" Then SL = I : I = 1
Next I
If SL = 0 Then Print "INVALID CIDR STRING: '"; CI$; "'": Goto 140
NW = Val(Mid$(CI$,SL+1))
If NW < 1 Or NW > 32 Then Print "INVALID NETWORK WIDTH:"; NW: Goto 140
REM PARSE OCTETS INTO IP ARRAY
BY = 0 : N = 0
For I = 1 To SL-1
C$ = Mid$(CI$,I,1)
If Not (C$ <> ".") Then
IP(N) = BY : N = N + 1
BY = 0
If IP(N-1) < 256 Then 310
Print "INVALID OCTET VALUE:"; IP(N-1): Goto 140
Else C = Val(C$):If C Or (C$="0") Then BY = BY*10+C
Type IPAddress
octets(3) As Integer
End Type
Function isDigit(Byval ch As String) As Boolean
Return (Asc(ch) >= Asc("0")) And (Asc(ch) <= Asc("9"))
End Function
Function ParseIPAddress(cidr As String, Byref networkWidth As Integer) As IPAddress
Dim As IPAddress ip
Dim As Integer slashPos = Instr(cidr, "/")
Dim As String ipPart = Left(cidr, slashPos - 1)
networkWidth = Val(Mid(cidr, slashPos + 1))
Dim As Integer i, currentOctet = 0, octetValue = 0
For i = 1 To Len(ipPart)
If Mid(ipPart, i, 1) = "." Then
ip.octets(currentOctet) = octetValue
currentOctet += 1
octetValue = 0
Elseif IsDigit(Mid(ipPart, i, 1)) Then
octetValue = octetValue * 10 + Val(Mid(ipPart, i, 1))
End If
310 '
Next I
IP(N) = BY : N = N + 1
If IP(N-1) > 255 Then Print "INVALID OCTET VALUE:"; IP(N-1): Goto 140
REM NUMBER OF COMPLETE OCTETS IN NETWORK PART
NB = Int(NW/8)
REM NUMBER OF NETWORK BITS IN PARTIAL OCTET
XB = NW And 7
REM ZERO Out HOST BITS IN PARTIAL OCTET
IP(NB) = IP(NB) And (255 - 2^(8-XB) + 1)
REM And SET Any ALL-HOST OCTETS To 0
If NB < 3 Then For I = NB +1 To 3 : IP(I) = 0 : Next I
REM Print Out THE RESULT
Print Mid$(Str$(IP(0)),2);
For I = 1 To 3
Print "."; Mid$(Str$(IP( I)),2);
Next I
Print Mid$(CI$,SL)
Loop
Data "87.70.141.1/22", "36.18.154.103/12", "62.62.197.11/29"
Data "67.137.119.181/4", "161.214.74.21/24", "184.232.176.184/18"
REM SOME INVALID INPUTS
Data "127.0.0.1", "123.45.67.89/0", "98.76.54.32/100", "123.456.789.0/12"
Next
ip.octets(currentOctet) = octetValue
Return ip
End Function
Function ApplyNetworkMask(ip As IPAddress, networkWidth As Integer) As IPAddress
Dim As IPAddress result = ip
Dim As Integer completeOctets = networkWidth \ OCTET_BITS
Dim As Integer remainingBits = networkWidth And 7
' Apply mask to partial octet
If completeOctets < 4 Then
result.octets(completeOctets) And= (MAX_OCTET - 2^(OCTET_BITS-remainingBits) + 1)
' Zero remaining octets
For i As Integer = completeOctets + 1 To 3
result.octets(i) = 0
Next
End If
Return result
End Function
Function ValidateInput(ip As IPAddress, networkWidth As Integer, cidr As String) As Boolean
If Instr(cidr, "/") = 0 Then
Print "INVALID CIDR STRING: '"; cidr; "'"
Return False
End If
If networkWidth < MIN_NETWORK Or networkWidth > MAX_NETWORK Then
Print "INVALID NETWORK WIDTH:"; networkWidth
Return False
End If
For i As Integer = 0 To 3
If ip.octets(i) > MAX_OCTET Then
Print "INVALID OCTET VALUE:"; ip.octets(i)
Return False
End If
Next
Return True
End Function
Sub ProcessCIDR(cidr As String)
Dim As Integer networkWidth
Dim As IPAddress ip = ParseIPAddress(cidr, networkWidth)
If Not ValidateInput(ip, networkWidth, cidr) Then Exit Sub
ip = ApplyNetworkMask(ip, networkWidth)
Dim As String result = Str(ip.octets(0))
For i As Integer = 1 To 3
result &= "." & Str(ip.octets(i))
Next
Print result & "/" & networkWidth
End Sub
' Main program
Dim As String cidr(9) = { _
"87.70.141.1/22", "36.18.154.103/12", "62.62.197.11/29", _
"67.137.119.181/4", "161.214.74.21/24", "184.232.176.184/18", _
"127.0.0.1", "123.45.67.89/0", "98.76.54.32/100", "123.456.789.0/12" }
For i As Integer = 0 To 9
ProcessCIDR(cidr(i))
Next
Sleep