why connection always gets refused? - python

I am trying to connect machine using the RPyC but it always says that connection refused.
I did on the python shell
import rpyc
rpyc.connect("hostname", port)
but it says connection refused. checked the firewall for the port. firewall allow this port.

Try using the exact same versions of both python and rpyc on client and server !

This means that you are not runnin the server side for rpyc
you need to donwload the source code for rpyc from here
https://github.com/tomerfiliba-org/rpyc/releases
then run:
python bin/rpyc_classic.py
where bin is in the source code folder
Once you have that running, you should be able to run the python code without any issues
I hope it works

default server binds to localhost, but the client needs to have hostname 'None' to do this correctly:
rpyc.connect(None, port)

Related

Python - error with a simple socket script

So I wrote a script in Python with the module socket but finally he doesn't work. After searching a few hours for an error (I'm new in Python so it's long for me), I didn't find any so instead I wrote another simple script which works with netcat to have a reverse shell between my host machin (Linux) and my VM (Windows).
My command netcat with Linux :
nc -nvlp 4444
My script in Windows :
import socket
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect(("192.168.1.81", 4444))
And after start the listener (netcat), he's listening and after a few seconds, in my Windows machin, the scripts closed itself because he doesn't find anything connection.
I don't know where is the problem, my VM is on the same subnet than my host, I've flushed my iptables in Linux just in case, I'm lost :)
Thanks for your answers !
I just send the script to a friend for trying and it's working, so I think so the problem is in my settings, or somewhere else..

PyCharm remote debugging (pydevd) does not connect

PyCharm remote debugging (pydevd) does not connect with the following message:
error: [Errno 10061] No connection could be made because the target machine actively refused it
How can I troubleshoot it?
The output console in PyCharm shows:
Starting debug server at port 21000
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('*.*.*.*', port=21000, suspend=False)
Waiting for process connection...
Server stopped.
I checked the firewall and PyCharm is allowed for both incoming and outgoing connections.
10061 is WSAECONNREFUSED, 'connection refused', which means there was nothing listening at the IP:port you tried to connect to.
Though I see that you have validated its not a firewall issue, but still I would suggest to check the port numbers again with respect to the ones opened in windows firewall. Or to narrow down just run a simplehttpserver or icmp server at the same port and confirm.
In a direct link communication, it often means that you have already something connected to this port.
To check what process is hearing what port, check this SO question.
You can then either kill the program or change the port, depending of what you can do.
Without more information of the "remote tested", it is hard to know what is happening.
I was having the trouble as well (Server stopped as soon as the client connected).
Turned out that I had apparently too many breakpoints defined.
after having removed most of them and re-initiated my remote debug connection from the client (and having restarted the debug server in pycharm) it doesn't trigger anymore the "Server stopped." problem.

Cannot connect to python SimpleHTTPServer but can connect to apache

I was setting up a public Ipython Notebook in my remote Ubuntu 12.04 server according to http://ipython.org/ipython-doc/1/interactive/public_server.html#notebook-public-server, but when all was done, I cannot connect to it via both chrome and safari (in both https and http modes), I got timeout error in chrome, safari told me server isn't responding. So I tested the system by setting up following simple python server:
python -m SimpleHTTPServer
And the same error occured. I also checked the port with sudo netstat -anltp|grep :8000, which seems fine:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 22683/python
What surprises me is that I have the apache running and holding websites just fine (I also try to turn it off when configuring python server but that didn't help). Can anyone give me a clue what might be wrong in the Ubuntu server and how I should debug it?
I have found the issue: it turns out that the ports are closed by firewall, although in netstat it says python is listening to port 8000, but when incoming request reaches port 8000 it is rejected before getting to python server. By opening the ports the issue can be well resolved.
It turns out that the ports are closed by firewall, although in netstat it says python is listening to port 8000, but when incoming request reaches port 8000 it is rejected before getting to python server. By opening the ports the issue can be well resolved.

Python Socket Doesn't Work Between Host and VM

I am learning python socket programming. Everything works fine if I run locally (both server and client scripts). However, when I moved the server script to a VM (Ubuntu 14.04) and run the client script from the host os (Windows 7) I got this error:
ConnectionRefusedError: [WinError 10061] No connection could be made because the
target machine actively refused it
When I tried running the client inside the VM, it works just fine (except if I use the IP address i.e:192.168.1.6, I have to use it in both scripts). From my search, I found that linux does not activate the firewall by default. What did I do wrong?
Both machines can see each other ( i have set Samba between them, can ping others etc). This is really confusing for me.
Probably this may solve the problem.
You have a bind call in your server code, it looks like sock.bind(('127.0.0.1', 3333)), where 3333 is the server port number. Change the IP address to the empty string, or '0.0.0.0', so it would look like sock.bind(('', 3333)). Then start the client again.
The original bind call binds the server socket only to the loopback interface (lo), which works only within the VM. By binding to the wildcard address ('' or '0.0.0.0') the server will accept connections from any IP address.

Connecting to Python XML RPC from the Mac

I wrote an XML RPC server in python and a simple Test Client for it in python. The Server runs on a linux box. I tested it by running the python client on the same linux machine and it works.
I then tried to run the python client on a Mac and i get the following error
socket.error: (61, 'Connection Refused')
I can ping and ssh into the linux machine from the Mac. So i dont think its a configuration or firewall error.
Does anyone have any idea what could be going wrong?
The code for the client is as below:
import xmlrpclib
s = xmlrpclib.ServerProxy('http://143.252.249.141:8000')
print s.GetUsers()
print s.system.listMethods()
"Connection Refused" means the connection was REFUSED - the machine 143.252.249.141 is up, and in the network, but is not accepting connections on port 8000 - it is actively refusing them.
So maybe the server software isn't running on the server? Or is running in another port? Or is bound to a different IP address?

Categories

Resources