public static IPAddress GetExternalIP() { WebRequest request; WebResponse response; string ip; IPAddress finalIP; try { request = HttpWebRequest.Create("https://api.ipify.org"); request.Method = "GET"; response = request.GetResponse(); ip = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8).ReadToEnd(); if (!IPAddress.TryParse(ip, out finalIP)) { throw new UDProxyException("Invalid response from WhatIsMyIP: " + ip); } } catch { UDProxy.DebugWarn("NetUtils", "Could not get external IP, reverting to configuration."); return(IPAddress.Any); } UDProxy.DebugInfo("NetUtils", "Fetched external IP as " + ip); return(finalIP); }
private void StreamLoop() { while (true) { try { GetNextTransmission(); } catch { // Error, break out! break; } // No bytes == failure if (finalBytes == 0) { break; } packetReadStream = new MemoryStream(finalBuffer); try { MySocks.Process(packetReadStream, MyStream); } catch (Exception e) { packetReadStream.Close(); UDProxy.DebugException(e); break; } } DebugInfo("No more data left, closing stream and ending thread."); Console.WriteLine("___ CONNECTION END __________________________________"); Console.WriteLine( String.Format(" {0} bytes sent, {1} bytes received", UDPConnection.TotalUp, UDPConnection.TotalDown) ); if (UDPConnection.MyThread != null) { UDPConnection.MyThread.Abort(); } if (UDPConnection.MyUDP != null) { UDPConnection.MyUDP.Close(); } MyStream.Close(); MyConnection.Close(); }
private void DebugError(string msg) { UDProxy.Debug(this.GetType().Name, MyConnection.Client.RemoteEndPoint.ToString() + " | " + msg, UDProxy.DebugLevels.Error); }
public Configuration(string[] args) { Args = args; if (Config["MyExternalIP"] == null) { Config["MyExternalIP"] = NetUtilities.GetExternalIP(); } if (Array.IndexOf(args, "--nobatch") == -1) { Console.WriteLine("# I'm now going to ask you a few configuration questions."); Console.WriteLine("# Each question has a default or example answer in [Brackets]. Simply press [ENTER] to use it."); } if (Config["MyExternalIP"] == null) { while (true) { Config["MyExternalIP"] = Ask <IPAddress>("What is your external IP? (Check http://whatismyip.org)", "0.0.0.0") as IPAddress; if (Config["MyExternalIP"] != IPAddress.Any) { break; } Console.WriteLine("# 0.0.0.0 is not a valid external IP!"); } } if (Config["TargetIP"] == null) { IPAddress IPArgv = null; var validIP = (args.Length > 0) ? IPAddress.TryParse(args[0], out IPArgv) : false; if (!validIP) { Config["TargetIP"] = Ask <IPAddress>("What is the local IP of your server?", "192.168.0.32") as IPAddress; } else { Config["TargetIP"] = IPArgv; } } if (Config["TargetPorts"] == null) { List <UInt16> portListArgv = null; var validPorts = (args.Length > 1) ? TryParsePorts(args[1], out portListArgv) : false; if (!validPorts) { Config["TargetPorts"] = Ask <List <ushort> >("What are the ports of the regions of your server? (Seperate by comma)", "9000") as List <ushort>; } else { Config["TargetPorts"] = portListArgv; } } if (Array.IndexOf(args, "--nobatch") == -1) { var createBatch = (bool)Ask <bool>("Would you like to create a batch file to save these settings?", "yes"); if (createBatch) { var batchFile = File.CreateText("UDProxy.bat"); batchFile.WriteLine( System.AppDomain.CurrentDomain.FriendlyName + " " + Config["TargetIP"].ToString() + " " + List2CSV <ushort>((List <ushort>)Config["TargetPorts"]) + " --nobatch" ); batchFile.Flush(); batchFile.Close(); } } //if (Config["ListenIP"] == null) // Config["ListenIP"] = Ask<IPAddress>("What system IP do you want the SOCKS5 server to listen on?", "0.0.0.0") as IPAddress; //if (Config["ListenPort"] == null) // Config["ListenPort"] = Ask<ushort>("What system port do you want the SOCKS5 server to listen on?", "1080"); complete = true; Console.WriteLine(); UDProxy.DebugInfo("Configuration", "Configuration complete! I am..."); UDProxy.DebugInfo("Configuration", "> Redirecting UDP packets intended for: " + Config["MyExternalIP"].ToString() + ":" + AnonymousList2String <ushort>(Config["TargetPorts"])); UDProxy.DebugInfo("Configuration", "> ...to and from local server: " + Config["TargetIP"].ToString() + ":" + AnonymousList2String <ushort>(Config["TargetPorts"])); }