#!/usr/bin/ruby # need: ruby, pon, ifconfig, nslookup, curl, whois # run as root ! # parameter: stop or uk,ru,usa # CHANGE THIS VALUES: LAN_GATEWAY_IP = "10.0.0.1" LAN_DNS_IP = "10.0.0.1" # the default pptp server (in /etc/ppp/peers/ivacy!): PPTP_HOST = "pptp.ivacy.com" # Default Parameter: param = 'usa' if ARGV.size == 1 then param = ARGV[0] end #Wrong Parameter? if not param.match /uk|ru|usa|stop/ then puts "Parameter: stop or uk,ru,usa" exit end puts "Param: #{param}" if param == 'stop' then puts "Stopping PPTP-Connection and switch to default." `poff ivacy` `route add -net default gw #{LAN_GATEWAY_IP}` `echo 'nameserver #{LAN_DNS_IP}' > /etc/resolv.conf` # Stop Sock Daemon `killall -9 sockd` exit end hosts = {'ru' => 'pptp2.ivacy.com', 'uk' => 'pptp3.ivacy.com', 'usa' => 'pptp4.ivacy.com'} pptp_host = hosts[param] # Find pptp IPs: ns = `nslookup #{pptp_host}` ns.match /Address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/ pptp_ip = $1 # Change pptp IP @ /etc/hosts file = File.open '/etc/hosts' hosts = "" file.each do |line| if not line.match /#{PPTP_HOST}/ then hosts += line end end hosts += "#{pptp_ip} #{PPTP_HOST}\n" file.close file = File.new("/etc/hosts", "w") file.write(hosts) file.close # Create pptp Server route `route add -host #{pptp_ip} gw #{LAN_GATEWAY_IP} &> /dev/null` puts "Establish VPN Connection with #{pptp_host} (#{pptp_ip})..." # Establish PPTP Connection: `pon ivacy` # Wait for Connection: begin ip_remote = nil ppp0 = `ifconfig ppp0 2> /dev/null` if ppp0.match /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) P-t-P:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) / then ip_remote = $2 ip_local = $1 puts "Established VPN-PPTP Connection :)" end end while ip_remote == nil net_local = ip_local.gsub /\.[0-9]+$/, '.0' net_remote = ip_remote.gsub /\.[0-9]+$/, '.0' dns_primary = ip_remote.gsub /\.[0-9]+$/, '.2' dns_secondary = ip_remote.gsub /\.[0-9]+$/, '.3' puts "Local IP: #{ip_local} [#{net_local}]" puts "Remote IP: #{ip_remote} [#{net_remote}]" # Setup routing table `route del -net default &> /dev/null` #`route add -net #{net_remote}/24 ppp0 &> /dev/null` `route add -net default gw #{ip_remote} ppp0 &> /dev/null` # DNS Update: `echo 'nameserver #{dns_primary}' > /etc/resolv.conf` `echo 'nameserver #{dns_secondary}' >> /etc/resolv.conf` # Start Dante-Socks Daemon `sockd -D`