Anyone knows if it is possible to create a socket connection in C# using a (public) http proxy server?
Not sure what you mean exactly. Connect to a proxy server using c# to download? Check HttpWebRequest.Proxy
Nope, not exactly I am working on a asp.net page that checks if certain ports are open/listening But coming from my own IP it reports some ports open that should be closed to the outside (blocked by firewall, ip filter) So i was thinking if i could connect through a proxy it shouldn't report blocked ports being open for proxy ip
Is the code executed server or client side? It's server. I Checked. Any firewall exceptions from the server to your IP?
Server, eg: Code: public static bool ScanPort(string host, int port, int type) { bool open = false; try { IPAddress ip = (IPAddress)Dns.GetHostAddresses(host)[0]; Socket sock; if (type == 2) { sock = new Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Udp); } else { sock = new Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp); } IAsyncResult result = sock.BeginConnect(ip, port, null, null); bool success = result.AsyncWaitHandle.WaitOne(3000, true); if (!success) {// Port is unused and could not establish connection open = false; } else {// Port is open open = true; } sock.Close(); } catch (System.Net.Sockets.SocketException ex) { if (ex.ErrorCode == 10061) {// Port is unused and could not establish connection open = false; } else { open = false; } } return open; }
Well. First of all UDP is connectionless so you can't check that. Are the ports which appear open UDP? Also Open is not the same as Listening. If the port is open but there is no socket waiting for connections on that port it will not appear open.
ok ditched the UDP part... Example: port 110 / 995 should be closed from outside, but appears open/listening (because my ip is allowed)
pm. the ip you're checking. I'll check from here. Soz. you gave the host. I'll check and report back. Open. I'll check with a scanner from work. I'd guess there is a rule from the server to your host which is allowed.
I understand now. In that case the answer is no. Proxies only support HTTP protocols and there are special http headers written to tell the proxy the endpoint http address. A socket proxy does not exist. What you need is a port forwarder but that means it must be configured to accept connections and make them to the endpoint.