How do I connect/disconnect/configure a wireless network in python? - python

I'm looking to see if there is a way to connect or disconnect to a wireless network in python, preferably a way that would work for both public and secured networks if I supplied the password. If I can configure the options about wireless, that would be an added bonus (ex. see all networks in range, see information about networks in range (like encryption type)). I run a windows computer, so I see many answers to this question in Linux, or other operating systems, but none in windows. Thanks in advance.

You'll probably have to use one of the DLLs in windows for that. Using ctypes you can get access to the win32 API from Python.
It looks like the functions from wlanapi.dll, starting with WlanOpenHandle and WlanEnumInterfaces might do what you want.
Edit: For example code, see the accepted answer to this.

Related

Connect two devices using DDS on Lan

I came up with an idea to establish connection between my Raspberry Pi 4 and Windows host machine. I did it successfully by utilizing MQTT protocol, but got interested in Data Distribution Service concept (DDS). My Pi needs to send captured images (publish) to windows machine (subscriber) as byte array. How to do this easily for prototyping and testing purposes? I don't have a problem with doing this on same machine, but cannot wrap my head around connectivity between nodes on same LAN network, I know for sure that DDS supports TCP and UDP. Is there just an config file where I have to put IP addresses of second machine for both applications and that's it? I want to use RTI Connector for Python, can it work on its own for both devices that communicate? Sorry for lame question, but I just want to test DDS utility as fast as possible. Can anyone point me to some sources that would help solve my case? I've seen some articles, but none were clear to me.
Most of the answers that you're looking for can be found on community.rti.com.
But fundamentally, you should be able to run DDS between your Raspberry Pi and Windows box easily...and the helloworld should run with no configuration required (Connext DDS uses multicast for discovery by default)...as long as you have disabled the firewalls on your Linux (assuming you're running Linux on the Raspberry Pi) and on Windows (usually not needed if the network type is configured to be private).
If you want to use Python as the programming language you can either use the new Python API for RTI Connext DDS,
or as you mentioned, RTI Connector for Python (although this will be deprecated since RTI has released the Python API).
Examples are provided in the distributions of both the Python API for Connext as well as RTI Connector (with documentation).
You will need to understand a bit about DDS to modify the examples to use your own data type. Basically it means defining your data type in IDL and then using rtiddsgen to generate the XML definition of the datatype from IDL...or you can directly create your datatype definition in XML.
[I tried to add a bunch of links to the documentation, examples, etc., on github/rti.com/community.rti.com, but it got flagged as SPAM]
If your datatype is a fixed size array, then you should use the IDL fundamental datatype of octet[]. If it's variable sized, then you need to use sequence, either
struct MyImageType {
octet imageFrame[1048576];
};
or
struct MyImageType {
sequence<octet, 1048576> imageFrame;
};
using the above in an IDL file and then using rtiddsgen will be easier than typing the equivalent XML definition into a file.

Programmatic access to Brother ADS-1000W

I've got a Brother ADS-1000W receipt scanner and using the ControlCenter4 software it works great. However I would like to be able automate the scanning process and I can't find any pointers/clues on where to get access to the ADS-1000W specific features. With the ControlCenter4 software, I can have the scanner deskew images. It also scans to an arbitrary length and width (matching the scanned receipt). I'm assuming this is being handled by the scanner, but it may be happening in the ControlCenter4 software. These features specifically don't seem to be accessible in the TWAIN interface. I tried using TWAINCommander 3 and it doesn't show the deskew and arbitrary size features in the TWAIN interface.
I've got both Linux and Windows machines available and I'm cool with a commandline solution or an SDK that I have to write software to implement. If it's an SDK, I prefer Python.
I know this is somewhat open-ended, but hoping someone can point in a direction for further research.
Just in case anyone else stumbles across this question: The ADS-1000W supports scanning to FTP. If PDF is selected, then the scanner supports the de-skew option, so I installed vsftpd on my linux box and used Python to process the files as their uploaded.

How to write specific data to a smart card using Python

In my project I'm trying to use a smart card for the purpose of creating digital signature for a specific data.
I'm working with the smart card reader ACR38U-I1 and Linux OS (more precisely with the Raspbian OS)
I already installed all the needed drivers for this device and additional libraries such as pcsc, pcsc-lite ...
Also I got private/public gpg keypair for making the digital signature.
As I understand the concept of making digital signature using smart card I have to write the private key to this card and read it when I need to create a signature.
And in this situation I faced with a problem that I don't know how to do this.
I opened pcsc-lite documentation [1] and couldn't find a write methods or examples how to write data to card
https://pcsclite.alioth.debian.org/api/group__API.html [1]
I'll be grateful if somebody could direct me on the right way.
The typical approach is:
generate the key (pair) on the smart card; this has the advantage, that no malicious software will be able to grab the private key since it will never leave the card.
send the command to generate a signature to the card, e.g. with the hash value of the data to sign
Reading the key from the smart card discards all the security a smart card provides. The most common way to generate a signature is using a PKCS 11 software, but it may be difficult to find one for Raspbian. I would recommend to find a card directly supported by GPG. That way you will not need to learn in detail about all the necessary topics.
(Wanted to write a comment, but it got quite long...)
(EDIT: While writing this I did not realize that you are working in a non-x86 environment, so this answer is probably useless unless you have a choice to go for x86 (intel edison maybe?))
This is not a solution, but might be a good direction (I have no experience with this particular card):
There is a PKCS#11 driver for the card which probably provides some access to its services (pkcs11 is a standardized API to access cryptographic tokens, see here).
With this driver (assuming it works and provides appropriate mechanisms) you have some choices to continue:
use it directly from c code (works for me)
use a python wrapper (have no experience with this way, but your question implies python is desired)
use openssl (see e.g. here or here -- this worked for me some time ago)
use it with gpg (never tried and would not recommend at all)
It might be a good idea to verify first that the pkcs11 driver is working (you can do that using firefox browser, see e.g. here).
Additional notes:
I recommend to initialize the card and generate the keys with vendor provided utilities and use the pkcs11 driver only to actually sign some data (this way avoids many troublesome parts).
Do google for pkcs11 and related stuff, this "extended comment" is just an another "point of view"
Good luck!

put interface down in windows with python?

A friend asked me for a program to switch his integrated wifi card off and on. I've googled it with no luck. Can someone tell me if there's any way to do that natively in python?
Does the solution have to be native? I would use a utility called 'devcon' which is created by Microsoft. You could use Python to call devcon and parse the output and disable the required device(s).
Here's an example:
http://en.kioskea.net/faq/1886-enable-disable-a-device-from-the-command-line
You can get the list of network devices with
devcon hwids =net
You can try to parse the one with WiFi in it and the lines that start with PCI.
Or you can do something like:
devcon disable hwids =net, unfortunately this disables the ethernet devices as well.
If you need to just disconnect from WiFi you can use netsh wlan disconnect
EDIT: Ok, finally found the perfect solution (IMHO).
You will need to install two packages pywin32 and wmi.
Using WMI (Windows Management Instrumentation) bindings for Python this becomes pretty easy.
import wmi
cur=wmi.WMI()
wireless_devices=cur.query("select * from Win32_NetworkAdapter WHERE NetConnectionID = 'Wireless Network Connection'")
for device in wireless_devices:
device.Disable()
If it returns a tuple with the first value of (0) it succeeded. Obviously, this must be run as an administrator (otherwise you will get 5 as the return value).
If there is a way to do it from the win32 API in C/C++ (I honestly don't know), then you can use the pywin32 bindings to do it from Python.

Achieve AVRCP using Pybluez in Linux

I want to make my PC as AVRCP bluetooth controller (CT) and handle a device which supports AVRCP bluetooth profile This has to be done using python scripting. Can I achieve this from pyBluez. If yes can some one give me some pointer of how to achieve this.
Thanks in Advance
There is a new Linux Bluetooth Stack supporting AVRCP. See here.
There seems to be an implementation of AVRCP in Python here.
Have a look at it and try it.
I'm also exploring this area. Further to the links provided by Radu, I've found https://trac.ctdo.de/ctdo/browser/btctl/src/pyavrcp which appears to implement the controller (CT) side of AVRCP, as well as the target (player).

Categories

Resources