-
Notifications
You must be signed in to change notification settings - Fork 1
/
varnish_atack.rb
161 lines (147 loc) · 4.33 KB
/
varnish_atack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#! /usr/bin/env ruby
# -*- coding:utf-8 -*-
load File.dirname(__FILE__) + '/models.rb'
require 'mechanize'
require 'json'
require 'uri'
def get(args)
agent = Mechanize.new #省メモリ(but低速)を期待,メモリガベージコレクタが都度破棄してくれれば...
agent.user_agent_alias = 'Windows IE 7'
args[:p] ||=1
args[:per]||= 100
if(args[:useproxy])
agent.set_proxy('192.168.110.7', 3129)
else
agent.set_proxy('192.168.110.7', 3128)
agent.read_timeout = 5
end
url = "#{args[:uri]}?p=#{args[:p]}&per=#{args[:per]}&qs=#{URI.encode(args[:qs])}"
puts url
agent.get url
pj = JSON.parse agent.page.body
if pj[0].next == "yes"
return get({
useproxy:true,
uri:args[:uri],
p:args[:p] + 1,
per:args[:per],
qs:args[:qs],
})
else
puts "end of search #{args[:qs]}"
end
rescue => ex
puts ex
puts "end this qs attempt : #{args[:qs]}"
end
def main_genre(useproxy)
#http://192.168.110.7/musicdb_dev/api/search_by_genre?p=2&per=5000&qs=VOCALOID
args = {}
if useproxy
args[:uri] ||= "http://modeverv.dyndns.org/musicdb_dev/api/search_by_genre"
args[:useproxy] = true
else
args[:uri] ||= "http://192.168.110.7/musicdb_dev/api/search_by_genre"
end
Genremodel.all.only(:name).to_a.sort.each do |g|
args[:qs] = g.name
get(args)
end
end
require 'pp'
def get_s(url,useproxy)
agent = Mechanize.new #省メモリ(but低速)を期待,メモリガベージコレクタが都度破棄してくれれば...
agent.user_agent_alias = 'Windows IE 7'
agent.set_proxy('192.168.110.7', 3129) if(useproxy)
agent.read_timeout = 10
agent.get url
rescue => ex
pp ex
case(ex)
when Net::HTTP::Persistent::Error
puts "do nothing"
when Net::HTTPServiceUnavailable
puts "sleep 2"
sleep 2
end
end
class M
attr_accessor :artist
def initialize(m)
@artist = m
end
end
@threads = []
def main_title
Musicmodel.all.only(:artist).distinct(:artist).to_a.sort.each do |m|
m = M.new(m)
puts "#{m.artist}"
=begin
@threads << Thread.new do
get_s("http://192.168.110.7/musicdb_dev/api/scrape/similar?artist=#{URI.escape m.artist}",false)
end
@threads << Thread.new do
get_s("http://192.168.110.7/musicdb_dev/api/scrape/bio?artist=#{URI.escape m.artist}",false)
end
@threads << Thread.new do
get_s("http://192.168.110.7/musicdb_dev/api/scrape/wikipedia?artist=#{URI.escape m.artist}",false)
end
@threads << Thread.new do
get_s("http://192.168.110.7/musicdb_dev/api/scrape/bio?artist=#{URI.escape m.artist}",false)
end
@threads << Thread.new do
get_s("http://192.168.110.7/musicdb_dev/api/scrape/wikipedia?artist=#{URI.escape m.artist}",false)
end
=end
@threads << Thread.new do
get_s("http://modeverv.dyndns.org/musicdb_dev/api/scrape/similar?artist=#{URI.escape m.artist}",true)
end
@threads << Thread.new do
get_s("http://modeverv.dyndns.org/musicdb_dev/api/scrape/bio?artist=#{URI.escape m.artist}",true)
end
@threads << Thread.new do
get_s("http://modeverv.dyndns.org/musicdb_dev/api/scrape/wikipedia?artist=#{URI.escape m.artist}",true)
end
@threads << Thread.new do
get_s("http://modeverv.dyndns.org/musicdb_dev/api/scrape/bio?artist=#{URI.escape m.artist}",true)
end
@threads << Thread.new do
get_s("http://modeverv.dyndns.org/musicdb_dev/api/scrape/wikipedia?artist=#{URI.escape m.artist}",true)
end
if(@threads.size > 200)
@threads.each do |t|
puts "joining ...."
t.join
end
@threads = []
end
end
end
ts = []
ts << Thread.new do
# main_title
main_genre(true)
end
ts << Thread.new do
# main_genre(false)
end
ts << Thread.new do
agent = Mechanize.new
agent.user_agent_alias = 'Windows IE 7'
agent.set_proxy('192.168.110.7', 3128)
url = "http://192.168.110.7/mediadb2/api/dirs?qs="
agent.get url
url = "http://192.168.110.7/mediadb2/"
agent.get url
agent = Mechanize.new
agent.user_agent_alias = 'Windows IE 7'
agent.set_proxy('192.168.110.7', 3129)
url = "http://modeverv.dyndns.org/mediadb2/api/dirs?qs="
agent.get url
url = "http://modeverv.dyndns.org/mediadb2/"
agent.get url
end
ts.each do |t|
t.join
end
# ruby /home/seijiro/sinatra/musicdb_dev/varnish_atack.rb