File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,24 @@ function ip2location:checkip(ip)
401401 return R .IPV4 , ipnum , ipindex
402402 end
403403
404+ -- check for format ::FFFF:1.11.111.111 for ipv4
405+ local chunks = {ip :match (" ^%:%:[fF][fF][fF][fF]%:(%d+)%.(%d+)%.(%d+)%.(%d+)$" )}
406+ if # chunks == 4 then
407+ local ipnum = bn .ZERO
408+ local octet = 0
409+ for x ,v in pairs (chunks ) do
410+ octet = tonumber (v )
411+ if octet > 255 then return R .ERROR end
412+ ipnum = ipnum + (bn (octet ) << (8 * (4 - x )))
413+ end
414+
415+ local ipindex = 0 ;
416+ if self .ipv4indexbaseaddr > 0 then
417+ ipindex = ((ipnum >> 16 ) << 3 ):asnumber () + self .ipv4indexbaseaddr
418+ end
419+ return R .IPV4 , ipnum , ipindex
420+ end
421+
404422 -- check for ipv6 format, should be 8 'chunks' of numbers/letters
405423 -- without leading/trailing chars
406424 -- or fewer than 8 chunks, but with only one `::` group
You can’t perform that action at this time.
0 commit comments