I am trying to write a Python script to identify USB devices that did not get auto-mounted correctly in Linux. I am currently using subprocess and calling lsusb to gather the USB devices and then using PyUsb (A libusb 1.0 python wrap library) to find the category of the USB device so I can identify if it is a Mass Storage Media. What I can't figure out is how to bridge the information I have into the mountpoint that belongs to that USB drive. I need a combination of Linux commands that will get me the information I can use to link a mountpoint to a specific USB device so I can use subprocess and some basic parsing to create the script. Or maybe some other way to do this with Python modules I haven't thought of using.
I found a way to do it using information from mount and fdisk. I wrote a python module that encapsulates everything if anyone has the need for something similar: https://github.com/arthurbayerlein/Python/blob/master/storage_media.py
Related
I want to get the names of the devices connected to my laptop hotspot using python
I searched a lot and I find module like wmi and platform that gives you some system information but I couldn't get the job done by them
First of all, It depends on your OS actually.
For windows;
https://www.geeksforgeeks.org/python-getting-all-the-wifi-devices-the-system-has-connected/
For Linux;
https://pypi.org/project/who-is-on-my-wifi/
I am working on a project which consists primly on detect a usb intrusion and execute some code. So first i need to know how to detect this usb insertion using python 3.6. Thank you
Perhaps something like this: https://github.com/Ming-Shu/How-to-detect-USB-plug-in-on-Windows-using-Python
and already answered here for python specific: How to detect a new usb device is connected on python
On Linux, you would want to be monitoring the mount or devices partitions.
We are testing networking devices to which test interaction is done using serial ports. Python 2.7 with Windows is used to achieve this using the PySerial module of Python.
The scripts are run using Robot framework.
We observe that the Robot logs do not contain the serial device interaction dialogues.
We tried checking on Robot framework forums and it is unlikely that such support exists at Robot framework level.
We need to implement this in Python.
How can the following be achieved:
I) Basic requirement: All script interaction with the (multiple) test devices on serial port needs to be captured into a log file
II) Advanced requirement: while the script is not actively interacting with the test device there has to be continuous background monitoring of the device under test over serial ports for any errors/crashes
Thanks!
I may be incorrect but perhaps you want to capture data sent/received between computer and device through serial port. If this is true then serial port sniffer will be required. Linux and mac os x does not support sniffing however you may use sniffing for windows.
I'm building a backup program which involves detecting when media available for backup is inserted. I've looked into detecting the insertion of backup media, and I'm going to use the file system watch service inotify on the /media/username directory.
The problem is that I've looked into this directory and there are folders that don't represent any currently available medium. How can I detect the list of currently available mediums (USBs, HDDs) and watch for any future ones? More technically, what are the characteristics of an actively available USB/HDD folder in the /media/username directory?
In Linux, you could use uevents from kernel and start sniffing for "ACTION"="add"
Please check the following links:
http://lwn.net/Articles/242046/
and Netlink socket:
http://www.kernel.org/doc/man-pages/online/pages/man7/netlink.7.html
Or use DBUS/HAL API bindings for Python http://ubuntuforums.org/archive/index.php/t-904706.html
Check dmesg messages and see exactly what was attached and to what partition was mounted
P.S.: Here is an example (on SO) of how to do it in Python using DBUS binding:
How can I listen for 'usb device inserted' events in Linux, in Python?
UPDATE
How to check if a path is mounted:
https://serverfault.com/questions/143084/how-can-i-check-whether-a-volume-is-mounted-where-it-is-supposed-to-be-using-pyt
I can detect it rather easily through monitoring the /dev/disks/by-label/ directory.
I am writing a Python Application running on linux. I want to be able to register and be notified by the system if a network cable is plugged in/ out.
I am already using pyUdev (python bindings for libUdev) in order to get notified for USB plug in events. However, because the network eth0 module (for example) always remains loaded (regardless of the cable being plugged in) , I dont get the information I require. It only works for if up/down events.
I have read a lot of posts on Windows WMI providing this functionality but none on linux. Am I looking in the right direction?
A python way of doing this (a python library) would be ideal as I want to integrate this with my program.
There are many ways to get the "UP" status of a network interface via polling, ranging from simply parsing ifconfig output, to reading the status of /proc/net/... pseudo-files.
However, for a way to be notified (i.e. not poll yourself) for such events, your best option on Ubuntu is to use the netplug package. It's not installed by default, you need to:
sudo apt-get install netplug
Some documentation is here: http://manpages.ubuntu.com/manpages/lucid/man8/netplugd.8.html
To set it up you need to tweak /etc/netplug/netplugd.conf and /etc/netplug/netplug scripts. For an example of those config files check out the section "Configuring netplug" at http://natisbad.org/dyn-net/index.html
With /etc/netplug/netplug you can have your own python script called when the network goes down/up, so you can generate your kind of event for your application.
Have you looked into netplugd command, I am not sure if a python wrapper exists but it should not be hard to parse the output