gfwlist2ipset 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gfwlist2ipset +51 -55
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58cc997f476e71ad84a6cd1d1b268195d587f346
4
- data.tar.gz: 78c1593784e47bdd4e1e68c455b58c75f0dcb965
3
+ metadata.gz: 6c12a0f17faa22ec9f211c3b4490f9866fb8442d
4
+ data.tar.gz: 6dc106f6498608d0e083003a14fa13863fb77ed8
5
5
  SHA512:
6
- metadata.gz: 21bb6a67e5fe18eb5f28ae2a216d8931fa05ec907d1907464d6febe0c2fd0792da88af95a0a210bcfa1bc9534a338f5c3fb398eb0285b8cdb432dd63b2fccae0
7
- data.tar.gz: a8f93340ec6eb6ba2b3fb32975bf825870ce7330e4918cf3808da5b34163fd55349475964b485cbf80d63fc05c296f0b0d7aa635e9ba430853db0b9960725a2f
6
+ metadata.gz: f9a740d0cbd497d4f8ddc95090d1d97e2aba8ed652d3b38941c520ed81e52d608657e0d3356ea18249d167097a38e1758bb848634f37704d43e8d97889c8696f
7
+ data.tar.gz: 7496d17e670b1c752cf9447be3c3f4659e050ff23f10ea08b44197d9952d60d3e83629598c44dcd5a53b81ca8ac0bf8a5076731e410f8d52e314366f7f2de884
@@ -6,7 +6,7 @@ require 'public_suffix'
6
6
 
7
7
  options = {}
8
8
  OptionParser.new do |opts|
9
- opts.banner = "Usage: gfwlist2ipset [options]"
9
+ opts.banner = 'Usage: gfwlist2ipset [options]'
10
10
 
11
11
  options[:ipset] = 'outwall'
12
12
  options[:output] = 'gfwlist.conf'
@@ -24,55 +24,57 @@ OptionParser.new do |opts|
24
24
  end
25
25
  end.parse!
26
26
 
27
- gfwlist_url = 'https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt'
27
+ gfwlist_url = 'https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt'
28
28
  extra_domains = [
29
- "appledaily.com.hk",
30
- "bbc.com",
31
- "blogspot.com",
32
- "fastly.net",
33
- "githubusercontent.com",
34
- "google-analytics.com",
35
- "google.as",
36
- "google.co.jp",
37
- "google.co.id",
38
- "google.co.th",
39
- "google.co.uk",
40
- "google.com",
41
- "google.com.hk",
42
- "google.com.tw",
43
- "googlesyndication.com",
44
- "s3.amazonaws.com",
45
- "s3.feedly.com",
46
- "cloudfront.net",
47
- "ace-cdn.atlassian.com",
48
- "wufoo.com",
49
- "nextmedia.com",
50
- "cxense.com",
51
- "krxd.net",
52
- "chartbeat.net",
53
- "slack-files.com",
54
- "fbinfer.com",
55
- "line.naver.jp",
29
+ 'admob.com',
30
+ 'akamaihd.net',
31
+ 'amazonaws.com',
32
+ 'appledaily.com.hk',
33
+ 'appledaily.com.tw',
34
+ 'bbc.com',
35
+ 'blogspot.com',
36
+ 'fastly.net',
37
+ 'githubusercontent.com',
38
+ 'google-analytics.com',
39
+ 'google.as',
40
+ 'google.co.jp',
41
+ 'google.co.id',
42
+ 'google.co.th',
43
+ 'google.co.uk',
44
+ 'google.com',
45
+ 'google.com.hk',
46
+ 'google.com.tw',
47
+ 'googlesyndication.com',
48
+ 's3.feedly.com',
49
+ 'cloudfront.net',
50
+ 'ace-cdn.atlassian.com',
51
+ 'wufoo.com',
52
+ 'nextmedia.com',
53
+ 'cxense.com',
54
+ 'krxd.net',
55
+ 'chartbeat.net',
56
+ 'slack-files.com',
57
+ 'slack-redir.net',
58
+ 'files.slack.com',
59
+ 'fbinfer.com',
60
+ 'line.naver.jp',
61
+ 'packages.gitlab.com'
56
62
  ]
57
63
 
58
64
  def get_hostname(rule)
59
- begin
60
- host = URI.parse(rule).host
61
- if PublicSuffix.valid?(host)
62
- return PublicSuffix.parse(host).domain
63
- elsif PublicSuffix.valid?('.' + host)
64
- tld = PublicSuffix.parse('.' + host).tld
65
- if tld.include?('.') and tld == host
66
- return tld
67
- end
68
- else
69
- puts 'Hostname not valid: ' + host
70
- end
71
- return nil
72
- rescue
73
- puts 'can not parse rule as url: ' + rule
74
- return nil
65
+ host = URI.parse(rule).host
66
+ if PublicSuffix.valid?(host)
67
+ return PublicSuffix.parse(host).domain
68
+ elsif PublicSuffix.valid?('.' + host)
69
+ tld = PublicSuffix.parse('.' + host).tld
70
+ return tld if tld.include?('.') && tld == host
71
+ else
72
+ puts 'Hostname not valid: ' + host
75
73
  end
74
+ return nil
75
+ rescue
76
+ puts 'can not parse rule as url: ' + rule
77
+ return nil
76
78
  end
77
79
 
78
80
  enc = open(gfwlist_url).read
@@ -92,25 +94,19 @@ plain.each_line do |line|
92
94
  elsif line.start_with? '.'
93
95
  line = line.sub('.', '')
94
96
  end
95
- if line.start_with? '!' or line.start_with? '[' or line.start_with? '@'
96
- next
97
- end
97
+ next if line.start_with?('!') || line.start_with?('[') || line.start_with?('@')
98
98
  line.chomp!
99
99
  if line.length > 0
100
- if not line.start_with? 'http'
101
- line = 'http://' + line
102
- end
100
+ line = 'http://' + line unless line.start_with? 'http'
103
101
  hostname = get_hostname(line)
104
- if hostname
105
- domains.push(hostname)
106
- end
102
+ domains.push(hostname) if hostname
107
103
  end
108
104
  end
109
105
 
110
106
  domains.concat extra_domains
111
107
  File.open(options[:output], 'w+') do |f|
112
108
  f.puts '# Generated by gfwlist2ipset at ' + Time.new.inspect
113
- if options.has_key?(:dns)
109
+ if options.key?(:dns)
114
110
  domains.sort.uniq.each do |domain|
115
111
  f.puts('server=/' + domain + '/' + options[:dns])
116
112
  f.puts('ipset=/' + domain + '/' + options[:ipset])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gfwlist2ipset
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nullizer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-22 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_suffix
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  version: '0'
53
53
  requirements: []
54
54
  rubyforge_project:
55
- rubygems_version: 2.4.6
55
+ rubygems_version: 2.5.1
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: gfwlist2ipset