ipip 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ipip/ipv4_database.rb +4 -6
- data/lib/ipip/ipv4_database_x.rb +14 -16
- data/lib/ipip/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dbe208c2b3d180ac34233c7ca6d6c3ad7130b9e
|
4
|
+
data.tar.gz: 2c24cfda56a8900ec359eb7b4fd4205e62c3d587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b96a71626ea307fbb227e3669d41cd630ff34696587d190e0f22402c8c104d77f758516632007f9299d7646199bd8f33c9a0baf2d0896c4d110ff5bb3f1fc55
|
7
|
+
data.tar.gz: 55bd9f42dffd62fd4646bd1e95a317e2430a3090029993fa14b5d2114fd854658ab25813d4434d03a6aa02e6c1100d47969b9c8ce4fe8fdc215c4572bb32f50d
|
data/lib/ipip/ipv4_database.rb
CHANGED
@@ -59,8 +59,6 @@ module IPIP
|
|
59
59
|
start = unpack_V(buffer[first_ip_offset, 4])
|
60
60
|
start_offset = start * IP_BLOCK_SIZE + FIRST_IP_NUMBER_INDEX_SIZE
|
61
61
|
|
62
|
-
data_offset = data_length = 0
|
63
|
-
|
64
62
|
lo, hi = 0, (offset - start_offset) / IP_BLOCK_SIZE
|
65
63
|
|
66
64
|
while lo < hi
|
@@ -76,13 +74,13 @@ module IPIP
|
|
76
74
|
end
|
77
75
|
|
78
76
|
start_offset += lo * IP_BLOCK_SIZE
|
79
|
-
return if start_offset == offset
|
77
|
+
return nil if start_offset == offset
|
80
78
|
|
81
|
-
|
79
|
+
data_pos = unpack_V(buffer[start_offset + 4, 3] + 0.chr)
|
82
80
|
data_length = unpack_C(buffer[start_offset + 7])
|
83
81
|
|
84
|
-
data_offset = offset +
|
85
|
-
data = buffer[data_offset, data_length].encode('UTF-8', 'UTF-8')
|
82
|
+
data_offset = offset + data_pos - FIRST_IP_NUMBER_INDEX_SIZE - OFFSET_NUMBER_SIZE
|
83
|
+
data = buffer[data_offset, data_length].to_s.encode('UTF-8', 'UTF-8')
|
86
84
|
end
|
87
85
|
|
88
86
|
[:C, :N, :V].each do |format|
|
data/lib/ipip/ipv4_database_x.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'socket'
|
2
2
|
require 'ipaddr'
|
3
|
+
require 'pry'
|
3
4
|
|
4
5
|
module IPIPX
|
5
6
|
|
@@ -7,15 +8,15 @@ module IPIPX
|
|
7
8
|
#
|
8
9
|
# The IPIP.net data file(ipip.datx) format in bytes::
|
9
10
|
#
|
10
|
-
#
|
11
|
-
# | 4 bytes
|
12
|
-
#
|
13
|
-
# | 256 *
|
14
|
-
#
|
15
|
-
# | offset -
|
16
|
-
#
|
17
|
-
# |
|
18
|
-
#
|
11
|
+
# ----------------------------------
|
12
|
+
# | 4 bytes | <- offset number
|
13
|
+
# ----------------------------------
|
14
|
+
# | 256 * 1024 bytes | <- first ip number index
|
15
|
+
# ----------------------------------
|
16
|
+
# | offset - 256 * 1024 - 4 bytes | <- ip index
|
17
|
+
# ----------------------------------
|
18
|
+
# | data storage |
|
19
|
+
# ----------------------------------
|
19
20
|
#
|
20
21
|
class IPv4DatabaseX
|
21
22
|
|
@@ -51,7 +52,6 @@ module IPIPX
|
|
51
52
|
return unless ip.ipv4?
|
52
53
|
|
53
54
|
nip = ip.hton
|
54
|
-
|
55
55
|
first_ip = unpack_C(nip)
|
56
56
|
ipdot = ip.to_s.split('.')
|
57
57
|
first_ip_offset = (first_ip * 256 + ipdot[1].to_i) * 4
|
@@ -59,9 +59,7 @@ module IPIPX
|
|
59
59
|
start = unpack_V(buffer[first_ip_offset, 4])
|
60
60
|
start_offset = start * IP_BLOCK_SIZE + FIRST_IP_NUMBER_INDEX_SIZE
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
lo, hi = 0, (offset - start_offset) / IP_BLOCK_SIZE
|
62
|
+
lo, hi = 0, (offset - start_offset - OFFSET_NUMBER_SIZE) / IP_BLOCK_SIZE
|
65
63
|
|
66
64
|
while lo < hi
|
67
65
|
mid = (lo + hi) / 2
|
@@ -78,11 +76,11 @@ module IPIPX
|
|
78
76
|
start_offset += lo * IP_BLOCK_SIZE
|
79
77
|
return if start_offset == offset
|
80
78
|
|
81
|
-
|
79
|
+
data_pos = unpack_V(buffer[start_offset + 4, 3] + 0.chr)
|
82
80
|
data_length = unpack_C(buffer[start_offset + 8])
|
83
81
|
|
84
|
-
data_offset = offset +
|
85
|
-
data = buffer[data_offset, data_length].encode('UTF-8', 'UTF-8')
|
82
|
+
data_offset = offset + data_pos - FIRST_IP_NUMBER_INDEX_SIZE - OFFSET_NUMBER_SIZE
|
83
|
+
data = buffer[data_offset, data_length].to_s.encode('UTF-8', 'UTF-8')
|
86
84
|
end
|
87
85
|
|
88
86
|
[:C, :N, :V].each do |format|
|
data/lib/ipip/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liluo
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.4.8
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: IP search based on ipip.net
|