Python

Testing the Amazon Time Sync NTP Service with Python

Jim Lawless
I’d just read a new article describing Amazon’s new publicly available NTP service (Amazon Time Sync). You can read the article here: https://aws.amazon.com/about-aws/whats-new/2022/11/amazon-time-sync-internet-public-ntp-service/ I thought I’d give it a try with a Python script. I first needed to add ntplib to my local Python libraries: pip install ntplib Then, I put together this short script (amazontime.py): import ntplib from time import ctime ntp = ntplib.NTPClient() response = ntp.request("time.aws.com") print(ctime(response.tx_time)) Here’s the invocation and the output:

Using Python to Remove Image Backgrounds

Jim Lawless
A couple of weeks ago, I saw a notification containing a simple Python script that would remove backgrounds from images. The sample source code was something like this: from rembg import remove from PIL import Image inp = Image.open('image.jpg') output = remove(inp) output.save('image.png') I tried it. The results were pretty impressive. Without providing any parameters to speak of, a number of images that I used to test the library were transformed into images highlighting a central person or object while rendering the background transparent.

Black Hat Python - Python Programming for Hackers and Pentesters - 2nd Edition

Jim Lawless
I had read the first edition of this book in 2015-ish. That version was very intriguing, but it exclusively used Python version 2 for all examples. This was a time when the language was known to be in transition to version 3, although many were doing so somewhat cautiously, if at all. The 2nd edition of this book covers the same material with updates that include usage of Python 3 and the appropriate counterpart libraries.

Play MP3 Files in Windows with Python

Jim Lawless
Portions of this post were previously published on Sun, 26 Jun 2011. I read the book Grey Hat Python : Python Programming for Hackers and Reverse Engineers by Justin Seitz. The book introduced the Python ctypes library to me. The ctypes library, allows a Python program to access to lower-level features of the operating environment normally reserved for C programmers. As an early experiment, I rewrote in Python the bulk of the command-line MP3 player I had originally written in C.