static void Main(string[] args) { var httpProxy = new HttpProxy(); httpProxy.Start(); Console.ReadKey(); }
/// <summary> /// Start all the servers /// </summary> internal static void StartServers() { try { // start HTTP PROXIES foreach (var proxy in Config.Proxies) { var prox = new HttpProxy(proxy); _proxies.Add(prox); prox.Start(); } // start TCP FORWARDER foreach (var forwarder in Config.TcpForwarders) { var fwd = new TcpFwd(forwarder); _tcpForwarders.Add(fwd); fwd.Start(); } // start UDP FORWARDER foreach (var forwarder in Config.UdpForwarders) { var fwd = new UdpFwd(forwarder); _udpForwarders.Add(fwd); fwd.Start(); } } catch (Exception e) { ErrorHandler.LogErrors(e); MessageBox.Show("Error starting the servers :\r\n\r\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { var httpProxy = new HttpProxy(); WriteLineColor(ConsoleColor.Blue, @" ___ ___ /___\/ _ \_ __ _____ ___ _ // // /_)/ '__/ _ \ \/ / | | | v.0.0.1.alpha by lontivero / \_// ___/| | | (_) > <| |_| | \___/\/ |_| \___/_/\_\\__, | |___/ "); try { httpProxy.Start(); httpProxy.OnRequestHeaders += async(sender, e) => { var request = e.Session.Request; if (request.Uri.Host.Contains("facebook.com")) { e.Session.Abort(); } if (!request.RequestLine.IsVerb("CONNECT") && request.Uri.Host.Contains("lavoz.com.ar")) { await e.Session.ReturnResponseAsync(new Ok()); } }; httpProxy.OnResponse += (sender, e) => { try { var request = e.Session.Request; var response = e.Session.Response; var line = request.RequestLine; var status = response.StatusLine.CodeString; var url = line.Verb == "CONNECT" ? line.Uri : request.Uri.ToString(); WriteLineColor(ConsoleColor.White, $"{line.Verb,-7} {status, -7} {url}"); } catch (Exception ex) { WriteLineColor(ConsoleColor.Red, ex.ToString()); } }; WriteLineColor(ConsoleColor.Green, "Listening on http://127.0.0.1:8888"); } catch (SocketException se) { WriteLineColor(ConsoleColor.Red, se.SocketErrorCode == SocketError.AddressAlreadyInUse ? "There is another process listening at the same port!!" : "There was an unexpected error ;("); } Console.ReadKey(); }
public void TestMethod1() { var port = 9988; var proxy = new HttpProxy(port); proxy.OnRequestHeaders += (s, e) => { Assert.AreEqual("www.google.com", e.Session.Request.Headers.Host); }; proxy.Start(); var httpClientHandler = new HttpClientHandler() { Proxy = new WebProxy(new Uri($"http://127.0.0.1:{port}")), }; var c = new HttpClient(httpClientHandler); var res = c.GetAsync("http://www.google.com").Result; proxy.Stop(); }
static void Test3() { //var _server = new NetServer(); //var _server = new DNSServer(); var _server = new HttpProxy(); //_server.Port = 8888; _server.Log = XTrace.Log; _server.SocketLog = Logger.Null; //_server.SessionLog = Logger.Null; _server.SessionLog = XTrace.Log; _server.Start(); while (true) { //var svr = _server.Servers[0] as TcpServer; var svr = _server; Console.Title = "会话数:{0} 连接:{1} 发送:{2} 接收:{3}".F(_server.SessionCount, svr.StatSession, svr.StatSend, svr.StatReceive); Thread.Sleep(1000); } }
protected override void OnStart(string[] args) { _logger = new Logger(); try { var contentServers = new List<IPEndPoint> { new IPEndPoint(new IPAddress(new byte[] {127, 0, 0, 1}), 8081), new IPEndPoint(new IPAddress(new byte[] {127, 0, 0, 1}), 8082) }; var endPoint = new IPEndPoint(new IPAddress(new byte[] {127, 0, 0, 1}), 80); var portListener = new PortListener(endPoint); _httpProxy = new HttpProxy(contentServers, portListener, new RequestMessageBuilder(), new ResponseStreamWriter()); _httpProxy.Start(); } catch (Exception ex) { _logger.LogException(ex); } }
public override void Init(Kernel kernel) { PluginOptions = new PluginConfiguration <PluginOptions>(kernel, this.GetType().Assembly); PluginOptions.Load(); var trailers = (kernel.ItemRepository.RetrieveItem(TrailersGuid) as MBTrailerFolder) ?? new MBTrailerFolder(); trailers.Path = ""; trailers.Id = TrailersGuid; //validate sort value and fill in //int sort = 0; //int.TryParse(PluginOptions.Instance.SortOrder, out sort); //if (sort > 0) trailers.SortName = sort.ToString("000"); //Logger.ReportInfo("MBTrailers Sort is: " + trailers.SortName); kernel.RootFolder.AddVirtualChild(trailers); if (Kernel.LoadContext == MBLoadContext.Service || Kernel.LoadContext == MBLoadContext.Core) //create proxy in core and service (will only listen in service) { string cachePath = PluginOptions.Instance.CacheDir; if (string.IsNullOrEmpty(cachePath) || !System.IO.Directory.Exists(cachePath)) { cachePath = System.IO.Path.Combine(ApplicationPaths.AppConfigPath, "TrailerCache"); if (!Directory.Exists(cachePath)) { Directory.CreateDirectory(cachePath); } } long maxBandwidth = 1000 * 1024; long.TryParse(PluginOptions.Instance.MaxBandWidth, out maxBandwidth); if (maxBandwidth < 0) { maxBandwidth = 1000 * 1024; } else { maxBandwidth = maxBandwidth * 1024L; } proxy = new HttpProxy(cachePath, ProxyPort); if (Kernel.LoadContext == MBLoadContext.Service) { //only actually start the proxy in the service Logger.ReportInfo("MBTrailers starting proxy server on port: " + ProxyPort); proxy.Start(PluginOptions.Instance.AutoDownload, maxBandwidth); //and clean up the cache if requested if (PluginOptions.Instance.AutoClearCache) { MediaBrowser.Library.Threading.Async.Queue("MBTrailers cache clear", () => { while (true) { trailers.CleanCache(); System.Threading.Thread.Sleep(24 * 60 * 60000); //once per day } }); } } else { if (proxy.AlreadyRunning()) { Logger.ReportInfo("MBTrailers not starting proxy. Running in service."); } else { Logger.ReportInfo("MBTrailers - no proxy running. Start Media Browser Service."); } } //load mytrailers option if specified if (PluginOptions.Instance.ShowMyTrailers) { localTrailers = kernel.ItemRepository.RetrieveItem(MyTrailersGuid) as LocalTrailerFolder ?? new LocalTrailerFolder(); localTrailers.Id = MyTrailersGuid; kernel.RootFolder.AddVirtualChild(localTrailers); kernel.ItemRepository.SaveItem(localTrailers); //make sure our image cache is there if (!Directory.Exists(Util.ImageCache)) { try { Directory.CreateDirectory(Util.ImageCache); } catch (Exception e) { Logger.ReportException("Error Creating MyTrailers Image Cache: " + Util.ImageCache, e); } } //Tell the log we loaded. Logger.ReportInfo("My Trailers Support Loaded."); } //refresh the paths of trailers, but wait a bit in case the service side isn't up yet (we load before the service) MediaBrowser.Library.Threading.Async.Queue("MB Trailers refresh", () => trailers.RefreshProxy(), 3000); //tell core our types are playable (for menus) kernel.AddExternalPlayableItem(typeof(ITunesTrailer)); kernel.AddExternalPlayableFolder(typeof(MBTrailerFolder)); } Logger.ReportInfo("MBTrailers (version " + Version + ") Plug-in loaded."); }
private static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: boxxy.exe \"Port\" \"Sync directory\" \"Destination host\""); return; } bool interactive = args.Length == 4 && args[3] == "i"; if (interactive) { Console.WriteLine("Starting in INTERACTIVE mode, all requests are automatically PAUSED."); } else { Console.WriteLine("Starting in NON-INTERACTIVE mode, all requests are automatically FORWARDED."); } Console.WriteLine("Press ENTER to continue."); Console.ReadLine(); string listeningPort = args[0]; string syncPath = args[1]; string destination = args[2]; if (!Directory.Exists(syncPath)) { Console.WriteLine("Invalid sync directory, exiting."); return; } string[] files = Directory.GetFiles(syncPath, "*.json"); var requests = new List <IncomingHttpRequest>(); foreach (var file in files) { try { using (var reader = new StreamReader(file)) { string str = reader.ReadToEnd(); requests.Add(IncomingHttpRequest.FromString(str)); Debug.WriteLine("Deserialized request from file {0}", str); } } catch (SecurityException e) { ReadFailed(file, e); } catch (UnauthorizedAccessException e) { ReadFailed(file, e); } catch (IOException e) { ReadFailed(file, e); } } var store = new ProxyStore(syncPath, requests); var proxy = new HttpProxy(store, interactive); proxy.Start(string.Format("http://localhost:{0}/", listeningPort), destination); try { new MainScreen(store).Run(); } catch (QuitMenu) { // Intentionally ignored, the exception is only used for control flow. } }
private void Initialize() { AppendLog("RotMG Tool initializing..."); try { Settings = new SimpleSettings(); string packetFile = Path.Combine(Program.RootDirectory, "packets.dat"); if (File.Exists(packetFile)) { PacketTable = PacketTable.Load(File.ReadAllText(packetFile)); } AppendLog("Settings loaded."); } catch (Exception ex) { AppendLog("Error when loading settings: " + ex.Message); return; } //new System.Threading.Thread(DoCheckUpdate) { IsBackground = true }.Start(); AppendLog("Retrieving server list..."); var doc = XDocument.Load("http://realmofthemadgodhrd.appspot.com/char/list?guid=" + Guid.NewGuid().ToString().Replace("-", "").ToUpper()); byte id = 1; Servers = doc.XPathSelectElements("//Server").Select(srv => new RemoteServer { Name = srv.Element("Name").Value, DNS = srv.Element("DNS").Value, Loopback = new IPAddress(new byte[] { 127, 0, 0, id++ }) }).ToArray(); AppendLog("Server list retrieved, total {0} servers.", Servers.Length); if (!InitializeComponent("Spam Filter", () => { Filter = new SpamFilter(this); Filter.LoadWordList(); })) { return; } if (!InitializeComponent("Handlers", () => { Commands = new CommandManager(); Hooks = new HookManager(); Invoke(new Action(() => Windows = new WindowManager(this, windowDropDown))); })) { return; } AppendLog("If you see any firewall warning, allow this program to pass!"); if (!InitializeComponent("Web Proxy", () => { WebProxy = new HttpProxy(this); WebProxy.Start(); BeginInvoke(new Action(() => { proxyLink.Text = new Uri(WebProxy.ProxyUrl).AbsoluteUri; })); })) { return; } if (!InitializeComponent("Socket Proxy", () => { SocketProxy = new SocketProxy(this); SocketProxy.Start(); })) { return; } if (!InitializeComponent("Policy Server", () => { PolicyServer = new PolicyServer(); if (!PolicyServer.Start()) { throw new Exception("Cannot start policy server! Try start as adminstrator/sudo!"); } })) { return; } new HttpHandler(this).Attach(); new SocketHandler(this).Attach(); BeginInvoke(new Action(() => timer.Start())); AppendLog("RotMG Tool initialized."); }