Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- using System.Net.Security;
- using System.Security.Cryptography.X509Certificates;
- namespace NTLMProxyTester
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length == 0)
- {
- Console.WriteLine("usage: <program.exe> http(s)://example.com proxyHost proxyPort proxyUsername proxyPassword proxyDomain...");
- return;
- }
- try
- {
- // setup where the request is going to
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(args[0]));
- Console.WriteLine(string.Format("Making request to: {0}", request.RequestUri.ToString()));
- ServicePointManager.ServerCertificateValidationCallback += delegate(
- object sender,
- X509Certificate certificate,
- X509Chain chain,
- SslPolicyErrors sslPolicyErrors)
- {
- bool validationResult = true;
- return validationResult;
- };
- // setup the request credentials
- NetworkCredential proxyCredentials = new NetworkCredential()
- {
- UserName = args[3],
- Password = args[4],
- Domain = args[5]
- };
- Console.WriteLine(string.Format("Proxy credentials:"));
- Console.WriteLine(string.Format(" - username: {0}", proxyCredentials.UserName));
- Console.WriteLine(string.Format(" - password: {0}", proxyCredentials.Password));
- Console.WriteLine(string.Format(" - domain: {0}", proxyCredentials.Domain));
- // setup the proxy details
- WebProxy proxy = new WebProxy(string.Format("{0}:{1}", args[1], args[2]), false);
- IWebProxy proxySettings = proxy;
- // associate the proxy settings with the NetworkCredentials directly
- proxySettings.Credentials = proxyCredentials;
- request.Proxy = proxySettings;
- Console.WriteLine(string.Format("Proxy address: {0}", proxySettings.GetProxy(request.RequestUri)));
- // make the request and deal with the response
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- {
- Console.WriteLine("Response incoming...");
- using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
- {
- Console.WriteLine(responseReader.ReadToEnd());
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment