Socket ssh connections remotely? - python

I wonder and i've been trying everything to get my program with python sockets to work remotely. When I say remotely is like, I run the server in my computer and my friend at his house can run the client and connect to my server. Is this possible without using Hamachi? Pls let me know, because I'm already dying by trying so many things and installing and uninstalling programs.

You have to activate port forwarding on your router so that everything that comes on the specific port is forwarded to your local IP (and the port should be open).

Related

How to connect Linux Virtual Machine from its host computer?

I'm creating a simple chat app using Python.
The server code is in the Linux VM (I am using Virtual Box), and the client code is in the Windows 10 computer where the Virtual Box is installed.
I'm trying to connect it with the Python socket.
It works when I ping both machines to each other.
My problem is what port should I put in the client code:
Client
import socket
import subprocess
cliente = socket.socket()
try:
cliente.connect(('192.168.1.33',9090))
cliente.send("1")
I tried every port available; however, nothing works. I think I am missing something to make this work.
First, You need to make sure that the port number passed to bind function in server code in Linux VM is the same port number used by connect function in your client.
Check this simple server-client example in python which is using port 12345 :
https://www.tutorialspoint.com/python/python_networking.htm
Second, (based on your comments) the IP address that should be used in client connect function is the IP address of the machine running the server code which is in your case the Linux VM. Try to run the shell command ifconfig in the Linux VM to get the IP address.
If this address didn't work you can change the network settings of the virtual machine to bridged instead of NAT and try again the ifconfig command and get the new IP address.
Doing SSH from the host machine to Linux Virtual machine will work great!!

Pycharm IDE coding on remote server with ssh

I wonder if there is any way to coding python with remote server data and run the python script on remote server with pycharm only installed on my local machine?
The remote server can be access by two ip address (ssh and ftp each), id and password.
But when I try to use pycharm professional project interpreter, there always an error like this (the ip address I used is for ssh):
I know the easiest way is install jupyter notebbok on my remote server, but I don't have permission to do that.

Execute python code over SSH

I need to write a python script which connects to the host over SSH and then somehow connects to a service sitting on localhost and performs a little interactive session.
What first came to mind is to use Paramiko to do a local port forwarding and then use Pythons's sockets library to communicate with the service.
But working with Paramiko was quite a challenge and I haven't figured out how to fix some issues.
So I switched to pxssh and used just simple scenario:
conn.sendline('telnet {} {}'.format('localhost', port)
conn.expect('PASSWORD:')
conn.sendline(password)
...
But that telnet thing really bothers me.
And I think it's possible to establish SSH connection in such a manner that from Python's code prospective I just do data = open('somefile').read() which actually opens a somefile on a remote host and all traffic is being encrypted because of SSH.

Quick issue with Python 3.1 http server

I'm have an issue with running the built in Python server that comes with 3.1, this may or may not be an issue with Python, in fact it probably isn't.
I start my server in the correct directory with "python -m http.server 8000" as the documentation suggests (http://docs.python.org/release/3.1.3/library/http.server.html).
When I navigate to that port on my local network with another computer using the url 192.168.2.104:8000 (my local ip and the port) my page loads. When I use my global IP, however, it stops working. Port 8000 is forwarded correctly. I used www.yougetsignal.com to verify that port 8000 was open using my global IP. Why in the world would Chrome be saying "Oops! Google Chrome could not connect to [REDACTED]:8000" then? Other server applications (such as my Minecraft server) work just fine. Is there something I'm missing? Furthermore, why would yougetsignal connect to my port but not Chrome?
With most routers ports are only mapped when someone connects from the outside (internet/WAN). You're testing it from your LAN so basically you're connecting to your router when you use your public IP. Ask a friend to test, i.e. from an outside connection.

How do I setup a python, telnet proxy for a device on a different network over SSH?

Overview:
I have a device sitting on a local network to a computer that is sitting on an outside network. I would like to create a software program that allows me to seamlessly connect to the device from a computer on a different network. For purposes of this question, I've created a picture to help describe the network flow. What I need help with is what python packages I would need to develop the solution for this problem.
Details:
I have a computer MYPC (IP address 192.168.0.168) that is attached to the internet running through a proxy server (ROUTER1). I have full control over MYPC's environment, which is running Linux.
I have a second computer SOMESERVER (IP address 192.168.1.168) that is attached to the internet running through a proxy server (ROUTER2). In addition, SOMESERVER (IP address 10.0.0.159) is also attached to a local network (LOCAL). SOMESERVER is running windows. I have very limited control with SOMESERVER: I am able to send an executable to SOMESERVER that can run once before it is removed. I do not know the internet/world IP address of the ROUTER2 initially.
I have a device (DEVICE1) attached to SOMESERVER through LOCAL (IP address: 10.0.0.157).
I have another device (DEVICE2) attached to SOMESERVER through LOCAL (IP address: 10.0.0.158). DEVICE(x) runs linux. I have python on DEVICE(x) and I could install a pure python package if I needed to. However, I do not have the ability to compile for DEVICE(x).
I can connect between SOMESERVER and MYPC through the internet using SSH over ROUTER1 and ROUTER2. I can connect between SOMESERVER and DEVICE1 through the local network (LOCAL) using Telnet. I can connect between SOMESERVER and DEVICE2 through the local network (LOCAL) using Telnet.
I want to send a program to SOMESERVER that allows me seamless access over SSH and Telnet to DEVICE1 and DEVICE2 from MYPC. In addition, I want that program to be running python.
Here's a picture that helps explain the above problem:
Solution:
What I think I want is as follows. I need help with the details and what packages I might need to make it happen.
Part 1: The Dial Home Client and Server
Create a "dial home" server program (DIAL_HOME_SERVER) for MYPC which listens for any one dialing home and then will "dial into" any SOMESERVER that "dials home" using SSH.
Create a "dial home" client program (DIAL_HOME_CLIENT) for SOMESERVER which is downloaded as part of a package
Part 2: The Proxy Server
Create a ssh to telnet proxy server program (PROXY_SERVER) for SOMESERVER which listens for connections from MYPC and funnels them into a telnet connection to DEVICE(x).
Thanks to Greg Hewgill, it sounds like I can use Paramiko to pull together the PROXY_SERVER code on SOMESERVER. It appears that Paramiko also requires PyCryto, and the Windows binary for it can be found here.
Future Robustness
At a future date, the telnet connection will be replaced with an SSH client (dropbox on DEVICE(x)).
In Closing
I think the above will allow MYPC to connect "seamlessly", but the details of how to put together these programs is unknown to me. I already know how to package up a python program using Innosetup and/or py2exe. What I'd love to see is links pointing to different pieces of the solution so I can pull it all together. And then I can post it.
Thanks in advance!
I have to admit that I didn't quite follow all of your description, especially the "dial home" client/server part. However, your diagram seems sufficient for understanding.
Set up port forwarding on "router2" that forwards the incoming SSH port to your Windows server.
Write a Python program (you will probably find paramiko helpful) that runs on your Windows server, listens for SSH connections, and opens a telnet connection to one of your devices on the back end.
That seems sufficient to me. If you've got weird restrictions on the Windows server about only being able to run an executable once before it is deleted, that seems like another problem to solve that doesn't really relate to this tunnelling problem.

Categories