SSH Access using Renci.SSH to MySQL Server - c#

Trying to access a MySQL server using the Renci host SSH library.
I got it working by following the info Creating a forwarded port within an SSH tunnel
Specifically this line got my local port sucessfully set up such that it could be bound:
ForwardedPortLocal port = new ForwardedPortLocal("localhost", 3306, "localhost", 3306));
This is fine, but as I understand it the SSH client is binding to 3306 to receive data back from the server. This is a problem if the user has MySQL already installed as it will be using this port so my service cannot. Of course the service can be stopped but this is not a very friendly process.
I was expecting to be able to pass a High - Ephemeral - Port to listen on for the duration of my connection.
I got a bit confused on which parameter I should pass, having originally thought the second port would be the local port I need to bind to. After extensive experimentation on port configs I am at a loss as to how to handle this.
In addition I tried various overloads but none of the 3 other overloads seemed to produce what I wanted.
Any tips?
Thanks,
Andy

Ok I've resolved this now.
The solution is to modify the MySQL connector string so it uses a Ephemeral port. Picked one at random.
server=localhost; uid=;pwd=; database=; port=14324
Then modify the ForwardedLocalPort to bind to this port.
ForwardedPortLocal port = new ForwardedPortLocal("localhost", 14324, "localhost", 3306);
So we're forwarding the connection to localhost 14324 to localhost 3306 on the remote server.
Next challenge how to ensure that the port I use isn't already bound!!
So to do this use the overload that does not require a port number i.e.
ForwardedPortLocal("localhost", "localhost", 3306)
This will allocate an available Ephemeral port to your process which can be found using:
port.Start();
var portNumber = port.BoundPort;
This can then be added to your MySQL connection string.

Related

How to connect to AWS RabbitMQ from C#?

In my C# application, I have this code:
var factory = new ConnectionFactory
{
Port = 5671,
UserName = "userxxxx",
Password = "passwordxxx",
HostName = "amqps://xxxx.mq.us-east-1.amazonaws.com"
};
using var connection = factory.CreateConnection();
But during the CreateConnection I receive:
RabbitMQ.Client.Exceptions.BrokerUnreachableException
HResult=0x80131620
Message=None of the specified endpoints were reachable
Source=RabbitMQ.Client
The AWS Console shows me:
Endpoint: amqps://xxxx.mq.us-east-1.amazonaws.com:5671
What am I doing wrong?
Use a tool like "netcat" to verify you can connect to port 5671 on the AWS MQ. Netcat should be used from the same host you are trying to connect from. Alternatively, consider using a cloud-based portscanner like https://www.whatismyip.com/port-scanner/ to take your local network out of the equation.
Successful example with netcat:
$ nc -vz myownawsmq.mq.us-east-1.amazonaws.com 5671
Connection to myownawsmq.mq.us-east-1.amazonaws.com 5671 port [tcp/amqps] succeeded!
If you get an error or timeout, then your URL is incorrect or port 5671 is blocked.
When I created my AWS RabbitMQ instance, port 5671 was open to the internet because publicly accessible is the default. You cannot use a security group with RabbitMQ instance that is publicly accessible. If you set Private Access for the RabbitMQ instance, you won't be able to reach it externally.
It's also possible 5671 is blocked by local firewall rules. Check the firewall configuration in your local network to make sure 5671 is allowed. If a cloud-based port scanner can connect to the port, but a local scan can't, it's probably your local network configuration.

Cant connect to mysql server when port is change c#

Im using xammp as my platform for my database
Usually the defualt port of mysql is 3306 and it is working properly
But when I change the port like 4444 in my.ini I have an error message receive
cannot connect to any of the specified mysql hosts
By using this connection string
string connectString = "datasource=xxx.xx.xx.xxx;port=4444;username=root;password="";database=XXXXX;";
Well XAMPP might require a restart of MySQL server in order to update open port. But according to Connector strings, parameter "Port" might be ignored if Unix socket is used. So you can also check that.
Also, I know that have PHP in title, but I think it might be connected with your problem. Try this and say if it helped

Connecting to Cassandra from remote machine

I want to ask for your help on how can connect to my Cassandra DB on my droplet from remote machine. I did everything that is written in this article: Install Cassandra but when I try to connect from my C# code:
cluster = Cassandra.Cluster.Builder()
.WithCredentials("abc", "abc")
.AddContactPoints(new[] { "12.34.56.78" })
.WithPort(9168)
.Build();
var session = cluster.Connect();
var keyspace = "Test";
session.CreateKeyspaceIfNotExists(keyspace);
session.ChangeKeyspace(keyspace);
I'm getting an Exception:
'Cassandra.NoHostAvailableException' in Cassandra.dll
Additional information: None of the hosts tried for query are available
(tried: 12.34.56.78:9168)
I also tried from other Cassandra GUI Clients like DBeaver but I'm getting the same error.
My Droplet is Ubuntu 14.04. From localhost I have no problem with Cassandra my only problem is from remote.
Here is result from
sudo netstat -plunt
Why could this be and how do I fix this?
You have to use port 9042.
listen_interface is used to setup inter-node communication.
The IP address or hostname that Cassandra binds to for connecting to other Cassandra nodes. Set this parameter or listen_interface, not both.
You have to change rpc_address and then restart cassandra daemon
(Default: localhost) The listen address for client connections (Thrift RPC service and native transport). Valid values are:
make sure you can run cqlsh locally, i.e. from the host where Cassandra is running. If you can not, check if Cassandra is running (check logs) and listens on the interface you are connecting to.
if you can connect locally, check you settings for rpc_address and rpc_broadcast_address for Cassandra. It should be set to other value than 'localhost' (which is set by default).
9042 port is for CQL by default, I suggest you not to reset it.

TCP Connect to Azure Fails

I recently deployed an Azure app to the staging environment which is supposed to accept TCP packets in port 2993. When run in the Azure emulator, it does this very well, and performs exactly as it should.
However, now that it is on Azure's staging servers, whenever I try to connect to the TCP port, i get the following SocketException:
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.
My web app has two instances, one is a worker role (it has 2993 configured in its endpoints) and a web role (only for port 80). Port 80, by the way, functions perfectly. The web app was created with Visual Studio in C#. Why is this happening and how can I fix it?
All help is greatly appreciated.
I would like to explain what was the issue and why adding above code solve this problem for others benefit.
In your worker role, you configure any TCP endpoint along with any port number. When this VM starts the VM is provisioned to use this port and firewall is included an exception to provide access to this port. By the time your is ready to start your Azure VM already have TCP/IP address and configured port is enabled.
Now when your role starts and if you have any service or application required access this port you really need to l
For example If I have Tomcat/Java configured in my worker role, I must have to create a TCP listener on my configured port. This can be done when my worker role starts as below:
Get the IP address and Port number of the current role instance
Create a TCP Listener and start on this IP address and Port
Add the code to perform step 1) and 2) in my worker role OnStart() function.
The code will look like as below:
TcpListener TomcatPortListener = new TcpListener(RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TomcatWeb80"].IPEndpoint);
TomcatPortListener.Start();
In your case you you did exactly the same you got the IP address and Port number from and then created an endpoint from a socket address using IP/Port:
RoleInstanceEndpoint externalEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TCPin"];
IPEndPoint localEndPoint = new IPEndPoint(externalEndPoint.IPEndpoint.Address, externalEndPoint.IPEndpoint.Port);
localEndPoint.Create();
It is a must setting for any web or worker role which create TCP endpoint.
It seems the problem had something to do with the program's detection of the server's IP address. By using the following server code instead, I managed to fix the problem:
RoleInstanceEndpoint externalEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TCPin"];
IPEndPoint localEndPoint = new IPEndPoint(externalEndPoint.IPEndpoint.Address, externalEndPoint.IPEndpoint.Port);
The IPEndpoint can then be used with the tcpListener socket.

No response from sever on external IP in client-server IM app

I'm following a tutorial # http://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1---Building-the-Chat-Client.html to try and gather the basics of networking. For those not wanting to hit the jump, it's a quick tut demonstrating how to program a simple client-server-model chat application.
When I try and run the code in the tut, it works fine as long as both the client and the server are on the same network, but the second I try and do it externally (getting a mate to run the client app, and running the server app my side), it all goes to pot. The fact that the code works when in the same network leads me to believe that it's not a coding issue, but an issue with the way my network is set up.
I'm trying to run the server on my IP address at port 21719, which I have opened, but still other people can't connect to my server, not able to get any form of response at all.
The code (from the tut) that is being used for the server to listen to connections is:
public void StartListening()
{
IPAddress ipaLocal = ipAddress; //ipAddress is parsed from txtIP
tlsClient = new TcpListener(ipaLocal, 21719);
tlsClient.Start();
ServRunning = true; //for the running loop
// Start the new tread that hosts the listener
thrListener = new Thread(KeepListening);
thrListener.Start();
}
Now, the tutorial does actually point out that
IPAddress ipaLocal = ipAddress;
Will cause issues on some configurations, and I'm beginning to fear that my configuration may be included in that.
So, does anyone have any solution for me?
Thanks,
Sam
What is the local IP address that you're using? (ipAddress) If it's 127.0.0.1, that's not correct (I don't know how it would work internally either, but Windows seems to use magic from time to time). Also, if you have multiple NICs in your local machine, maybe the port forwarding is only set up to forward to one of them, and you're using the IP of the other?
If that's not the problem, here are a few generic suggestions:
Grab a copy of netcat. It's a small network testing util whose only job is to form a simple TCP connection. That will allow you to eliminate your code as a variable in all this. If netcat can form a connection, then you know the problem is your code. If not, you've confirmed that it's your router.
You can use WireShark (or TShark) to look for ICMP packets. Capture ICMP packets on the remote machine. If you get "Destination Unreachable" from the router, you've again proved that it's your router.
As Spencer said you need to make sure Port Forwarding is setup on your router, to forward all packets that come in on port 21719 to your internal machine. As for exactly how to do that, it's hard to say without knowing what type of router.
Are you having people use your external (internet) IP address? (See yours here.)
Have you pinholed your router to forward all communications from port 21719 to your server?
Some tips:
What kind of operating system are you using? Please check the Scope and/or Profiles (under Advanced tab) of your firewall rule.
While your friend is trying to telnet to the port (connect to the im server) monitor the traffic using Wireshark or Network Monitor (Wireshark have problems with Vista and Win 7). If you don't see anything hitting your machine the problem is probably on the router side. Double check the settings - you said you set the forward rule (NAT) but did it also set the rule on firewall of your router?

Categories