I'm using SSH.NET for coding an GUI to create a connection to a VPS. My intention is to make a proxy server for playing online games.
I need to forward a port dynamically, to create a SOCKS Server and then, Proxifier (another program installed on my computer) can connect to this server.
When I use PuTTY, Proxifier works well, but when I use my software, it's not working.
This is my code:
using (client = new SshClient("VPS_IP", "USER", "PASSWORD"))
{
client.KeepAliveInterval = new TimeSpan(0, 0, 60);
client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 50);
port = new ForwardedPortDynamic("127.0.0.1", portNumber);
client.Connect();
client.AddForwardedPort(port);
port.Start();
if (client.IsConnected && port.IsStarted)
{
MessageBox.Show("Connected");
}
System.Threading.Thread.Sleep(20 * 1000);
}
And now, the log of Proxifier
[48:51] Testing Started.
Proxy Server
Address: 127.0.0.1:port
Protocol: SOCKS 5
Authentication: NO
[48:51] Starting: Test 1: Connection to the Proxy Server
[48:51] IP Address: 127.0.0.1
[48:51] Connection established
[48:51] Test passed.
[48:51] Starting: Test 2: Connection through the Proxy Server
[48:51] Authentication was successful.
[48:51] Error : connection to the proxy server was closed unexpectedly.
[48:51] Test failed.
[48:51] Testing Finished.
To debug problems with forwarded port, start by handling ForwardedPort.Exception event.
Once you find out what exception, if any, is raised, we can help you further.
Related
I have a c# socket server started on a windows server pc.
This is the code that make the server start :
appServer = new AppServer();
var m_Config = new ServerConfig
{
Port = 3000,
Mode = SocketMode.Tcp,
Name = "zonedetecserveur",
TextEncoding = "UTF-8"
};
//Setup the appServer
if (!appServer.Setup(m_Config))//Setup with listening port
{
Console.WriteLine("Failed to setup!");
Console.ReadKey();
return;
}
//Try to start the appServer
if (!appServer.Start())
{
Console.WriteLine("Failed to start!");
Console.ReadKey();
return;
}
Console.WriteLine("The server started successfully, press key'q' to stop it!");
This code works on the windows server pc, and the server start properly with the message "The server started successfully, press key'q' to stop it!"
But, when I try to reach the server by using :
//Create an instance
SocketClient = new Socket(SocketType.Stream, ProtocolType.Tcp);
IPAddress _ip = IPAddress.Parse(ip);
IPEndPoint point = new IPEndPoint(_ip, 3000);
//Make connection
SocketClient.Connect(point);
The application just crash with the error
System.Net.Internals.SocketExceptionFactory.ExtendedSocketException : 'A connection attempt failed because the connected party did not respond appropriately beyond a certain duration or an established connection failed because the connecting host did not respond. [::ffff:MY_SERVER_IP]:3000'
What I have done :
Open the port 3000 on my internet router so it can be receiving tcp things
Disable the firewall for the server.exe (it's basically the code I showed you on a cmd)
Trying different port
Note that when I put as an ip 127.0.0.1 and I start the server on my pc and send data to this ip it works perfectly fine.
Any help on why my server says it started but does not exist is appreciated.
Thank you
I have written a SFTP connection, which is connecting to a secure domain host (MBox location) in .NET Core:
IPHostEntry ip = Dns.GetHostEntry(Host);
using (SftpClient client = new SftpClient(ip.ToString(), Port, User, Password))
{
//connect to client
client.Connect();
var files = client.ListDirectory(PathToRead).ToList();
......
//wait for downloads to finish
await Task.WhenAll(tasks);
// disconnect the client by closing connection
client.Disconnect();
}
which is hosted in Azure App service with subscription and Azure AD configured as per my client's domain. When I am running the code I am seeing the following error:
Error in FTP connection. Exception: System.Net.Sockets.SocketException (11001): No such host is known
Can you please help.
ip.ToString() returns the name of the type, System.Net.IPHostEntry. Your SftpClient is then trying to look up System.Net.IPHostEntry in DNS and not finding anything, thus the exception.
I'm not familiar with the constructors provided by SftpClient, but presumably you need to do something like:
using (SftpClient client = new SftpClient(ip.AddressList, Port, User, Password))
i have faced a problem about H5 websocket
this is my server code by c# , i have open a port 3030 to run socket
WebSocketServer server = new WebSocketServer("ws://127.0.0.1:3030");
then in my website,i connected to server
var ws = new WebSocket("ws://www.yummyonline.net:3030");
but,the error throwed out
WebSocket connection to 'ws://www.yummyonline.net:3030/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
while i define like this in my website
var ws = new WebSocket("ws://127.0.0.1:3030");
it will work.
could anyone can teach me why ?
You tell your server to listen only on 127.0.0.1, therefore it will not be accepting connections on any other address or interface.
Try using WS://0.0.0.0:3030 as the binding to listen on all interfaces and addresses.
I'm trying to learn Socket Programming, and I encountered this error while connecting to my server application.
Here's my declaration of the TcpListener in the server application:
TcpListener listener = new TcpListener(IPAddress.Loopback, 5152);
and here's my declaration of the TcpClient in my client application:
TcpClient client = new TcpClient(Dns.GetHostEntry(IPAddress.Loopback).HostName, 5152);
I have read several questions like this, and I always get the same answer: Either the server application isn't listening to the port or not running at all. But I've double-checked the Resource Monitor and cmd using netstat to see if the service is listening to the port, and it is. I've also included the service in the Firewall exceptions, so I'm not sure why I keep getting this error while trying to connect to the server app.
Any ideas?
Dns.GetHostEntry(IPAddress.Loopback).HostName returns the host name of your machine. When you pass a host name to TcpClient, it will resolve it to one or more IP addresses using Dns.GetHostAddresses(hostName). This includes the public and link-local IP addresses of your machine (e.g., 192.168.15.4), but not the loopback address (127.0.0.1).
So your client is trying to connect to any of the non-loopback addresses of your machine, while your server is listening only on the loopback address. Thus, no connection can be established.
Solution: Connect to the same end point your server is listening on.
IPEndPoint endPoint = new IPEndPoint(IPAddress.Loopback, 5152);
TcpListener listener = new TcpListener(endPoint);
TcpClient client = new TcpClient();
client.Connect(endPoint);
I have a web service on a server in my company that we have restricted access to from all but one other server on our network.
I do however need to make calls to this from another machine. Is there a way I can spoof the other servers IP address in order to send an http request to the web service? I only need to send it info I don't need any returned data. It's for logging hits from another server on our main server.
I am using this
IPEndPoint endpointAddress = new IPEndPoint(IPAddress.Parse(ipAddress), 80);
using (Socket socket = new Socket(endpointAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
socket.SendTimeout = 500;
socket.Connect(endpointAddress);
socket.Send(byteGetString, byteGetString.Length, 0);
}
but get an exception
A connection attempt failed because
the connected party did not properly
respond after a period of time, or
established connection failed because
connected host has failed to respond
23.202.147.163:80
In general, it is not possible to establish a TCP connection with a server without being able to receive and process some reply packets from that server. HTTP is built upon TCP, and TCP starts communications with a "3-way handshake" that lets the client and server communicate.
The start of an HTTP request is not a single packet.
You could use a proxy to bounce your requests from an IP address that has access.