pcapr 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pcapr/pcapr.rb +12 -4
- data/lib/pcapr/version.rb +1 -1
- data/spec/pcapr_spec.rb +7 -4
- metadata +2 -2
data/lib/pcapr/pcapr.rb
CHANGED
@@ -2,6 +2,7 @@ require 'logger'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'patron'
|
4
4
|
require 'digest'
|
5
|
+
require 'timeout'
|
5
6
|
|
6
7
|
require 'fileutils'
|
7
8
|
|
@@ -51,9 +52,12 @@ class Pcapr
|
|
51
52
|
|
52
53
|
#获取该数据包文件
|
53
54
|
def pcap_file(pcap_url, file)
|
55
|
+
# set cookie
|
54
56
|
@driver.get(pcap_url)
|
55
|
-
|
56
|
-
|
57
|
+
res = @driver.get("/view/download")
|
58
|
+
File.open(file,"wb") do |f|
|
59
|
+
f.write(res.body)
|
60
|
+
end
|
57
61
|
end
|
58
62
|
|
59
63
|
def run(dir)
|
@@ -67,10 +71,14 @@ class Pcapr
|
|
67
71
|
file = File.join( proto_dir, File.basename(pcap_url).gsub(/\.html$/,"").tr("\\/:*?\"<>|"," ") )
|
68
72
|
logger.info " pcap file: #{file} save at '#{file}'"
|
69
73
|
begin
|
70
|
-
|
74
|
+
Timeout.timeout(60 * 60 * 2) do
|
75
|
+
pcap_file(pcap_url, file)
|
76
|
+
end
|
71
77
|
logger.debug " save ok"
|
72
78
|
rescue =>e
|
73
|
-
logger.error "
|
79
|
+
logger.error " save fail: #{$!}"
|
80
|
+
rescue Timeout::Error
|
81
|
+
logger.error " save fail: timeout in 2 hours"
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
data/lib/pcapr/version.rb
CHANGED
data/spec/pcapr_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'digest'
|
4
|
+
|
3
5
|
describe Pcapr do
|
4
6
|
before(:each) do
|
5
7
|
user= "bocycn@gmail.com"
|
@@ -46,13 +48,14 @@ describe Pcapr do
|
|
46
48
|
File.delete(file) if File.exist?(file)
|
47
49
|
@o.pcap_file(pcap_url,file)
|
48
50
|
File.should be_exist(file)
|
49
|
-
|
51
|
+
File.size(file).should == File.size(base)
|
52
|
+
Digest::MD5.hexdigest(File.read(file)).should == Digest::MD5.hexdigest(File.read(base))
|
50
53
|
File.delete(file) if File.exist?(file)
|
51
54
|
end
|
52
55
|
|
53
|
-
it "run try" do
|
54
|
-
@o.run( File.join($helper_dir,"me") )
|
55
|
-
end
|
56
|
+
#~ it "run try" do
|
57
|
+
#~ @o.run( File.join($helper_dir,"me") )
|
58
|
+
#~ end
|
56
59
|
|
57
60
|
|
58
61
|
end
|