Skip to content

Instantly share code, notes, and snippets.

@Youngv
Created June 22, 2018 09:42
Show Gist options
  • Save Youngv/10b92c874f5c4b91188e6a670b4037cc to your computer and use it in GitHub Desktop.
Save Youngv/10b92c874f5c4b91188e6a670b4037cc to your computer and use it in GitHub Desktop.
生成 PUBG 的专属 OpenVPN 配置
require 'json'
require 'netaddr'
require 'open-uri'
require 'nokogiri'
# azure香港 azure首尔
# aws釜山 aws首尔 aws东京
file = open('https://ip-ranges.amazonaws.com/ip-ranges.json') { |f| f.read }
data = JSON.parse(file)
aws_regions = %w[ap-northeast-1 ap-northeast-2 ap-northeast-3]
aws_ips = data['prefixes'].select { |x| aws_regions.include?(x['region']) && x['service'] = 'AMAZON' }.collect { |x| x['ip_prefix'] }.uniq
file = open('https://download.microsoft.com/download/0/1/8/018E208D-54F8-44CD-AA26-CD7BC9524A8C/PublicIPs_20180620.xml') { |f| f.read }
data = Nokogiri::XML(file)
azure_regions = %w[asiasoutheast asiaeast]
azure_ips = data.xpath('//AzurePublicIpAddresses/Region')
.select { |region| azure_regions.include?(region.attributes['Name'].value) }
.collect { |region| region.children }
.flatten
.collect { |ele| ele.attributes['Subnet'].value if ele.name == 'IpRange' }
.compact
ips = azure_ips + aws_ips
puts 'For OpenVPN'
ips.each do |ip|
ip = NetAddr::IPv4Net.parse(ip)
puts "route #{ip.extended} vpn_gateway"
end
puts "route 104.16.24.88 255.255.255.255 vpn_gateway"
puts 'For OpenConnect'
ips.each do |ip|
puts "route = #{ip}"
end
puts 'route = 104.16.24.88/255.255.255.255'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment