Where do messages go when using pythoncom.PumpMessages()? - python

I would like to know where does the function pythoncom.PumpMessage() stores the message when it comes into play. I was going through a site and just saw a Python Script for Key logger, I copied the code and used it on my computer but I don't feel safe, after deleting that code I think it's still running in the background and copying my keypresses. Is it so, please help.

If the python script was sending messages to anyone, you'd probably be able to tell by looking at the code. Somewhere there would be a block of code sending some file to a server.
As for PumpMessages(), it
Pumps all messages for the current thread until a WM_QUIT message.
According to this documentation. You can find other answered questions on this with a Google search as well. Pythoncom isn't sending any information to an external source in and of itself, however your script might be. You'd have to check your code for a block doing that.
As for it running after you delete the script, highly unlikely. If you didn't manually or programmatically (in the script) attach the Python script to some daemon, it isn't manifesting itself anywhere. You may be over-estimating the power of a basic Python keylogger. I wouldn't worry.
I've tried keyloggers before with pythoncom, and I've never had a problem. You can also look in the pythoncom library to find the PumpMessages() function and see if that is sending anything.

Related

write text from terminal of python code to a txt file?

I made a simple project in python that pings a server every few seconds and I want to store the ping data in a .txt file. (It might also be cool to put it in a GUI but I need it in a txt file for now). Also, it just shows the ping in the terminal so I have no idea how I would make it go into a txt because I'm new at coding.
(here's my code btw)
import os
import time
while 1:
os.system('ping 1.1.1.1 -n 1')
time.sleep(5)
I didn't try much because I couldn't figure out anything I looked up stuff and nothing was what I wanted.
(also I'm a noob at coding anyways)
You'll have to run your code with Popen instead of os.system (which is a bad idea in most cases, anyway, for security reasons).
With Popen (python.org -> documentation is your friend!) you can capture the output of the programs you run. You can then write that to a file object. (That's a built-in type in python. Again, official documentation on this is good and comes with examples!)
I honestly don't see a reason to write the results of ping to a file. Wouldn't you just care about whether that ping worked and was reasonably fast? Maybe extract that information instead and just log it instead!

What is needed to refactor this Twisted code for Python3.6?

Having trouble figuring out how to refactor some code written for Twisted under Python2.7 for Python3.6
I have been trying to figure out how to get the repository at https://github.com/stylesuxx/udp-hole-punching to work on Python3.6, using the Twisted library. According to the Readme, Python2.7 is required, although Twisted should work on Python3.5+. This leads me to believe that the problem is with the repository itself, although I can't figure out what to change.
I have run the code under Python2.7, and it works. The client and server will connect, and will output messages showing what connections are being made. Under Python3.5, however, no messages at all are output, and it essentially appears that nothing is happening at all. No error messages are displayed.
You might want to start with syntax changes, which your IDE if you use one should be highlighting, like changing print statements from
print 'text'
to
print('text')
See this cheat sheet and Porting Python 2 Code to Python 3 for more information.
Ok, I think I have the answer. I found this page: https://twisted.readthedocs.io/en/twisted-16.6.0/core/howto/python3.html.
I found the lines in server.py which started with "self.transport.write" and sent the message as bytes, rather than strings, by using an initial b or .encode(). I also changed the line if datagram == '0' to if datagram == b'0'.
Seems to be working so far. If I hit any more obstacles I will share it here.

Python: Running Daemon Processes in Windows7

I had a program that Scraped certain data from certain Web-Pages, and when the Web-Pages changed, acted accordingly.
How would one set up the program so it continues to run in the background?
I don't need any specifics
I'm just really confused on this concept and would appreciate whatever help anybody has to offer.
start path-to-pythonw.exe your-code.py
pythonw means without console.
start means start on background.
if your python is installed system-wide, you can probably start your-code.pyw
.pyw is associated with pythonw.exe
remember you cannot use print (to stdout) in this case.
If you want to be able to just start your process and have it background itself and do a few more typical things that "daemon" processes do in Unix, look here: How do you create a daemon in Python?
There is no concept of "background" in Windows. But the UNIX shell concept of a background process can be reasonably emulated by running your Python script as a Windows service. There are a couple of suggestions in this question: Is it possible to run a Python script as a service in Windows? If possible, how?
For casual use, I suggest that you learn how to use srvany from the second answer.
You simply need to leave your program running! Please google "python daemon" and see how to implement a persistent background process in Python.
Now, you cannot know when a website changes unless you poll it. If the website is well designed, the page you are trying to poll will have a "Last-Modified" header, you can make a "HEAD" request every so often (be nice: don't poll like crazy) and act when Last-Modified is >= than the one on record. If the site is not well designed, it will not have a reliable Last-Modified or ETAG header, in that case you will have to parse manually and check for changes yourself.
Cheers.

Pylons REPL reevaluate code in running web server

I'm programming in python on a pre-existing pylons project (the okfn's ckan), but I'm a lisper by trade and used to that way of doing things.
Please correct me if I make false statements:
In pylons it seems that I should say
$ paster serve --reload
to get a web server that will notice changes.
At that point I can change a function, save the file and then go to my browser to test the change.
If I want to examine variables in a function in the process of making a webpage, then I put raise "hello", and then when I load the page, I get a browser based debugger, in which I can examine the program.
This is all very nice and works swimmingly, and I get the impression that that's how people tend to write pylons code.
Unfortunately the reload takes several seconds, and it keeps breaking my train of thought.
What I'd like to do is to run the web server from emacs, (although a python REPL on the command line would be almost as good), so that I can change a function in the editor and then send the new code to the running process without having to restart it. (with a command line repl I guess I'd have to copy and paste the new thing, but that would also be workable, just slightly less convenient)
Python seems very dynamic, and much like lisp in many ways, so I can't see in principle any reason why that wouldn't work.
So I guess the question is:
Is anyone familiar with the lisp way of doing things, and with Pylons, and can they tell me how to program the lisp way in pylons? Or is it impossible or a bad idea for some reason?
Edit:
I can run the webserver from my python interpreter inside emacs with:
from paste.script.serve import ServeCommand
ServeCommand("serve").run(["development.ini"])
And I can get the code to stop and show me what it's doing by inserting:
import pdb
pdb.set_trace()
so now all I need is a way to get the webserver to run on a different thread, so that control returns to the REPL and I can redefine functions and variables in the running process.
def start_server():
from paste.script.serve import ServeCommand
ServeCommand("serve").run(["development.ini"])
server_thread=threading.Thread(target=start_server)
server_thread.start()
This seems to work, except that if I redefine a function at the REPL the change doesn't get reflected in the webserver. Does anyone know why?
It seems that this way of working is impossible in python for the reason given by TokenMacGuy's comment, i.e. because redefining a class doesn't change the code in an instance of that class.
That seems a terrible shame, since in many other respects python seems very flexible, but it does explain why there's no python-swank!

Python Libraries for FTP Upload/Download?

Okay so a bit of forward:
We have a service/daemon written in python that monitors remote ftp sites. These sites are not under our command, some of them we do NOT have del/rename/write access, some also are running extremely old ftp software. Such that certain commands do not work. There is no standardization among any of these ftp's, and they are out of our control(government).
About a year ago i wrote a ftp wrapper library for in house that basically adds in stuff like resume upload/resume download/verifying files are not currently being written to, etc. The problem is we soon found out is that due to so many of the ftp servers running werid/non standard software we were constantly fighting with the wrapper library/ftplib.
Basically I've given up on ftplib. Is there an alternative? I've looked at most of the ftp alternatives all of them are missing one or another key component of functionality.
What ever the choice is, it must run for python 2.5.2 (we cannot change). and must run on Linux/Windows/HP-UX.
Update:
Sorry i forgot to tell you alternatives i looked at:
ftputil, problem is it does not support resume upload/download and stuff like partially downloading files given an offset.
Pycurl looked good, i'll look at it again.
You don't mention which alternatives you've looked at already. Is ftputil one of them?
http://ftputil.sschwarzer.net/trac/wiki/Documentation
If you're trying to code around edge cases from various server implementations, you might be better off looking at the code used by Mozilla/Firefox. I imagine this is one of the things they have to deal with constantly.
You may have better luck with one of the cURL bindings such as pycURL.

Categories