Wątek przeniesiony 2018-05-22 12:51 z C# i .NET przez ŁF.

Blokowanie danego adresu po wciśnięciu przycisku

0

witajcie kochani,

chcialem odpalic proxy web titanium paczka Titanium.Web.Proxy. Najnowsza dostępna a wersja 3.0.213.

static void Main(string[] args)
{
    var proxyServer = new ProxyServer();
 
    proxyServer.TrustRootCertificate = true;
    proxyServer.BeforeRequest += ProxyServer_BeforeRequestAsync;
 
    var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true);            
 
    //An explicit endpoint is where the client knows about the existence of a proxy
    proxyServer.AddEndPoint(explicitEndPoint);
    proxyServer.Start();
 
    foreach (var endPoint in proxyServer.ProxyEndPoints)
        Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ",
            endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port);
 
    proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
    proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
 
    //wait here (You can use something else as a wait function, I am using this as a demo)
    Console.ReadLine();
 
    proxyServer.BeforeRequest -= ProxyServer_BeforeRequestAsync;
    proxyServer.DisableSystemHttpProxy();
    proxyServer.DisableSystemHttpsProxy();
    proxyServer.Stop();
}
 
private static async Task ProxyServer_BeforeRequestAsync(object sender, SessionEventArgs e)
{
    Console.WriteLine(e.WebSession.Request.Url);
    if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("google.com"))
    {
        await e.Ok("<!DOCTYPE html><html><body><h1>Website is blocked.</h1></body></html>", null);
    }
}

jak uzyskac w Form1 cos takiego, a nie w konsoli, aby po wpisaniu do textbox'a i uzyciu przycisku button blokowalo dany adres?
jak ten kod przeksztalcic? dziekuje za pomoc!!!

1

Coś mniej więcej takiego jak w załączniku. Musisz mieć listę blokowanych adresów i w ProxyServer_BeforeRequestAsync sprawdzasz, czy adres jest na liście.

0

Ok, mam, a można zrobić podgląd w osobnej formie co aplikacji robi w konsoli w danym momencie podczas nasłuchiwania?

1 użytkowników online, w tym zalogowanych: 0, gości: 1