Class: ProxyList
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #+(pl) ⇒ Object
- #-(pl) ⇒ Object
- #==(pl) ⇒ Object
- #_fixed(ip) ⇒ Object
- #find_all ⇒ Object
- #fix ⇒ Object
- #fix! ⇒ Object
- #fix_ips ⇒ Object
- #glypes ⇒ Object
-
#initialize(source = [], file = nil) ⇒ ProxyList
constructor
A new instance of ProxyList.
- #inspect ⇒ Object
- #ips ⇒ Object
- #ips_fixed ⇒ Object
- #load(file = @file) ⇒ Object
- #minus ⇒ Object
- #plus ⇒ Object
- #rehash ⇒ Object
- #reject ⇒ Object
- #save(mark = nil) ⇒ Object
- #standart ⇒ Object
- #to_pl ⇒ Object
- #valid ⇒ Object
Methods inherited from Array
Constructor Details
#initialize(source = [], file = nil) ⇒ ProxyList
Returns a new instance of ProxyList.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rhack/proxy/list.rb', line 56 def initialize(source=[], file=nil) if source.is String super [] load source elsif source.is Array raise ArgumentError, 'second arg must be a string' if file and !file.is String super source fix! if file @name = sort.hash @name = File.split(file)[1] if file and @name == 0 @file = file || "tmp/#{'%0*x'%[12,@name]}.txt" rw @file, map {|i| i*':'+"\n"} if file and !empty? else raise TypeError, "can't create proxylist from #{source.class}" end end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
51 52 53 |
# File 'lib/rhack/proxy/list.rb', line 51 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
52 53 54 |
# File 'lib/rhack/proxy/list.rb', line 52 def name @name end |
Instance Method Details
#==(pl) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/rhack/proxy/list.rb', line 76 def ==(pl) if pl.is ProxyList pl.name == @name else pl == self end end |
#_fixed(ip) ⇒ Object
116 117 118 |
# File 'lib/rhack/proxy/list.rb', line 116 def _fixed(ip) ip.is String and ip[/^\d+\.\d+\.\d+\.\d+$/] and !ip["\n"] end |
#find_all ⇒ Object
188 189 190 |
# File 'lib/rhack/proxy/list.rb', line 188 def find_all super end |
#fix ⇒ Object
102 103 104 |
# File 'lib/rhack/proxy/list.rb', line 102 def fix dup.fixprlist! end |
#fix! ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/rhack/proxy/list.rb', line 92 def fix! map! {|i| if i.is Array and ip = i[0] port = i[1].to_i [(ip.gsub!(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {|m| sprintf("%d.%d.%d.%d", *$~[1..4].map! {|d| d.to_i})} || ip), port > 0 ? port : i[1]] end }.compact! uniq! || self end |
#fix_ips ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rhack/proxy/list.rb', line 141 def fix_ips ts = [] (0...size).to_a.div(size/50).each {|d| ts << Thread.new {d.each {|i| if self[i][0].is Fixnum self[i][0] = self[i][0].to_ip next elsif self[i][1].to_i == 0 or self[i][0][/^\d+\.\d+\.\d+\.\d+$/] next end if (ip = self[i][0][/\d{1,3}[\.\-]\d+[\.\-]\d+[\.\-]\d{1,3}/]) self[i][0] = ip.gsub('-', '.') elsif $unres_hosts.has ip self[i] = nil else ip = IPSocket.getaddress(self[i][0]) rescue($unres_hosts << self[i][0]; nil) ip and (self[i][0] = ip) and tick! end }}} ts.joins && ts.clear compact! || self end |
#glypes ⇒ Object
132 133 134 |
# File 'lib/rhack/proxy/list.rb', line 132 def glypes reject {|i| i[1].to_i > 0} end |
#inspect ⇒ Object
106 107 108 109 110 |
# File 'lib/rhack/proxy/list.rb', line 106 def inspect @name.is(String) ? sprintf("<#ProxyList: %s (%d items)>", @name, size) : sprintf("<#ProxyList:%#0*x (%d items)>", 12, @name, size) end |
#ips ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/rhack/proxy/list.rb', line 120 def ips self[0].is(Array) ? self[0].size > 1 ? find_all {|i| i[1].to_i > 0 and _fixed i[0]}.firsts : find_all {|i| _fixed i[0]}.firsts : find_all {|i| _fixed i} end |
#ips_fixed ⇒ Object
136 137 138 139 |
# File 'lib/rhack/proxy/list.rb', line 136 def ips_fixed firsts.each {|ip| return false if !_fixed ip } true end |
#load(file = @file) ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/rhack/proxy/list.rb', line 177 def load(file=@file) if "\n".in file or "</".in file file.grabprlist self elsif File.file?(file) IO.read(file).grabprlist(self) else file.grabprlist self end self end |
#minus ⇒ Object
53 |
# File 'lib/rhack/proxy/list.rb', line 53 alias :minus :- |
#plus ⇒ Object
54 |
# File 'lib/rhack/proxy/list.rb', line 54 alias :plus :+ |
#rehash ⇒ Object
72 73 74 |
# File 'lib/rhack/proxy/list.rb', line 72 def rehash ProxyList self, @file end |
#reject ⇒ Object
192 193 194 |
# File 'lib/rhack/proxy/list.rb', line 192 def reject super end |
#save(mark = nil) ⇒ Object
171 172 173 174 175 |
# File 'lib/rhack/proxy/list.rb', line 171 def save(mark=nil) str = map {|i| i * ':' + "\n" if i.is Array} str = "#"*10+" #{puttime} - #{mark}\n#{str}"+"#"*20 if mark rw @file, str end |
#standart ⇒ Object
128 129 130 |
# File 'lib/rhack/proxy/list.rb', line 128 def standart find_all {|i| i[1].to_i > 0} end |
#to_pl ⇒ Object
112 113 114 |
# File 'lib/rhack/proxy/list.rb', line 112 def to_pl self end |