I'm trying to use a wlan adapter (TP-link TL-WN722N) in monitor mode to pick up RSS from signals in the environment (both beacons and clients). What I would like to do is to get the MAC address and RSS value into my own code somehow (preferably python). I'm planning to use these values for a rough estimate of locations of nearby devices.
I've looked into scapy, but it does not seem to provide RSS values.
tcpdump seems to be able to get both values, but I have been unable to catch client devices.
Is it possible?
If so can I filter MAC and RSS somehow?
I got it working with tcpdump!
To setup a monitor mode adapter, you first need to check which interface to use:
iw list
Select the correct phy (for me its phy1) and create an adapter (I called it moni0):
sudo iw phy phy1 interface add moni0 type monitor
Then add your adapter to the ifconfig:
sudo ifconfig moni0 up
See this guide for more details.
I used the following params for tcpdump to get the values that I needed. (you can pipe the output to your program, main.py in my case):
sudo tcpdump -n -e -tttt -vvvv -i moni0 | python main.py
You can find my project here.
Related
I executed this command in my Linux PC.
for p in /sys/class/drm/*/status; do con=${p%/status}; echo -n "${con#*/card?-}: "; cat $p; done
And this is the result.
DP-1: disconnected
DP-2: connected
HDMI-A-1: connected
HDMI-A-2: disconnected
My Linux PC has two DP ports, and I connected to two monitors.
One of the monitor is using adapter (from HDMI to DP)
Here I make a assumption, since one of the monitor is using adapter, so the result shows HDMI-A-1 is connected, instead of both DP are connected.
Is my assumption correct ?
I guess you are trying to detect if one monitor has been disconnected?
Here I make a assumption, since one of the monitor is using adapter,
so the result shows HDMI-A-1 is connected, instead of both DP are
connected.
Is my assumption correct ?
Most likely yes.
a) For more debugging I would run: lshw -short pickup a correct class and then do e.g. lshw -c display what is detected by the system.
b) You can also try to find the manufacturer of your device (you will probably need to install edid-decode for that):
ls /sys/class/drm/*/edid | xargs -n 1 edid-decode | grep Manufacturer:
When you unplug monitor or have a linux in virutal machine (like in my case) you will see a message:
Manufacturer: ### Model 0 Serial Number 0
c) You can also try disconnecting the monitor with the adapter and monitor it. You can do that by monitoring the change via udevadm monitor --property.
If you are trying to create a callback in linux I recommend reading the already answered question.
I've ecountered a problem using a serial GPS/GNSS device on a Raspberry Pi. The device in question is a u-blox GNSS receiver symlinked to /dev/gps.
I try to achieve logging the output data from this device and simultaneously sending correction data to it.
To be more specific, I use RTKLIBs (http://www.rtklib.com/) str2str tool for sending NTRIP/RTCM correction data to the GNSS receiver in order to get better position estimations using DGNSS/RTK.
The receiver's output data will be logged by a python script which is based on the GPS deamon (gpsd).
However, I guess the main issue is related to the serial port control.
When I run the writing process (str2str) first and afterwards any reading process (my python script/gpsd frontends (e.g. cgps) /cat) at the same time, the reading process will output data for a few seconds and freeze then. It doesn't matter which tool I use for reading the data.
I found this question: https://superuser.com/questions/488908/sharing-a-serial-port-between-two-processes. Therefore I made sure that the processes got rw access to the device and even tried running them as superuser. Furthermore I stumbled upon socat and virtual serial ports, but didn't find any use for it. (Virtual Serial Port for Linux)
Is there any way to read data from a serial port with one process and write to it with another? The only solution I know of right now might be to rewrite the read and write process in python using pySerial. This would allow to only have one process accessing the serial device, but would mean plenty of work.
Finally I found a soultion using a construction somehow similar to this: https://serverfault.com/questions/453032/socat-to-share-a-serial-link-between-multiple-processes
A first socat instance (A) gets GNSS correction data from a TCP connection, which is piped to socat B. Socat B manages the connection to the serial device and pipes output data to another socat instance C, which allows other processes such as gpsd to connect and get the receiver's output from TCP port.
In total, this looks like:
socat -d -d -d -u -lpA TCP4:127.0.0.1:10030 - 2>>log.txt |
socat -d -d -d -t3 -lpB - /dev/gps,raw 2>>log.txt|
socat -d -d -d -u -lpC - TCP4-LISTEN:10031,forever,reuseaddr,fork 2>>log.txt
With only one process managing the serial connection, it doesn't block anymore.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
Let's say I have paired and connected a Bluetooth headset successfully to my Linux system.
I know I can check my Bluetooth device MAC id from the bluetoothctl command.
Is there a way to control the Bluetooth device volume using some commands in Linux?
With this method, you need the appropriate D-Bus object path for the device to be controlled. There are a few ways of finding that (like using D-Feet), but once you have it, the following command will adjust the volume:
dbus-send --print-reply --system --dest=org.bluez /org/bluez/xxxx/yyyy/dev_zz_zz_zz_zz_zz_zz org.bluez.Control.VolumeUp
where "xxxx" seems to be the PID for bluetoothd, "yyyy" is the adapter (like "hci0"), "zz_zz_zz..." represents the MAC address of the controlled device (headset, speakers, etc.) separated by underscores, and 'VolumeUp' is replaced with 'VolumeDown' to decrease volume.
See the D-Bus documentation for more helpful on properly finding the object path. To do more than just adjust the volume, see the Bluez API documentation.
Not a proper answer, but an explanation: there are 2 different volumes for most bluetooth headsets: the software volume and the hardware volume. Traditionally on Linux you only control the software, however headsets can have an additional internal hardware volume, which is not possible to control currently. There are bug reports in place:
[BlueZ] Volume of bluetooth devices severly limited
AVRCP volume reporting for A2DP profile
If somebody knows how to control the hardware internal volume please reply below.
You can set the device's internal volume to a specific value instead of incrementing up or down using the shell:
Find the MAC address of your BT headset (we will replace colon with underscore for DBus-compatible MAC values):
$ bluetoothctl devices | sed "s/:/_/g"
Device A1_B2_C3_D4_E5_F6 Some Headset
Find the DBus object that allows control of the headset's internal volume:
$ dbus-send --system --print-reply --dest=org.bluez / org.freedesktop.DBus.ObjectManager.GetManagedObjects | less
While it is piped to less, search for the interface org.bluez.MediaTransport1 (press /, type MediaControl1, press Enter) and record the value of object path:
object path "/org/bluez/hci0/dev_A1_B2_C3_D4_E5_F6/sep1/fd0"
array [
dict entry(
string "org.bluez.MediaTransport1"
You should see a property named Volume in that block a few lines down
(if it is not present, the headset object does not support setting the volume directly):
dict entry(
string "Volume"
variant uint16 90
First get the current volume (here reported as 60):
$ dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_A1_B2_C3_D4_E5_F6/sep1/fd0 org.freedesktop.DBus.Properties.Get string:"org.bluez.MediaTransport1" string:"Volume" | grep uint16 | awk '{print $3}'
60
Let's increment the volume by ten - DO NOT GO STRAIGHT TO MAXIMUM OR LARGE VALUES as this may damage your equipment and/or your hearing.
$ dbus-send --system --dest=org.bluez /org/bluez/hci0/dev_A1_B2_C3_D4_E5_F6/sep1/fd0 org.freedesktop.DBus.Properties.Set string:"org.bluez.MediaTransport1" string:"Volume" variant:uint16:70
$ dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_A1_B2_C3_D4_E5_F6/sep1/fd0 org.freedesktop.DBus.Properties.Get string:"org.bluez.MediaTransport1" string:"Volume" | grep uint16 | awk '{print $3}'
70
On my equipment the range appears to be 0-127, with some values over 110 producing distortion. Take care with the values you supply to avoid damage.
I wanted to do device enumeration via PulseAudio as I have more than just Bluetooth devices I want to control. This relies on Sean's suggestion to use DBus to actually push the commands out to the Bluetooth devices. This script works in case you have multiple Bluetooth audio devices.
The Python library pulsectl makes finding these device identifiers easy. Sean's suggestion to use D-Feet was great to figure out the updated method name.
A mostly complete example is:
from pulsectl import Pulse
import subprocess
# diff applies to non-BT Pulse devices
diff = 0.1
method = 'org.bluez.MediaControl1.Volume{}'.format(
'Down' if diff < 0 else 'Up')
with Pulse() as pulse:
for sink in pulse.sink_list():
bluez_path = sink.proplist.get('bluez.path')
if bluez_path:
args = [
'dbus-send', '--system', '--print-reply',
'--dest=org.bluez', bluez_path, method,
]
subprocess.run(args, check=True)
else:
pulse.volume_change_all_chans(sink, diff)
I have something similar to this with diff coming from the command line, allowing relatively sane control over volume levels.
I used my i-phone to set the hardware volume in my Sony Headphones to MAX. Afterwords control for volume in Ubunto 20.04 LTS works fine.
Steps
Disconnect Blue-Tooth headphones from Ubuntu
Connect headphones to i-phone via Blue-Tooth
Open a YouTube video and adjust volume all the way up.
Disconnect headphones from i-phone
Connect Blue-Tooth headphones to your Ubuntu machine
The sound should now be fully adjustable.
Shell Scripting: How to calculate the number of bytes uploaded to a remote node?
1) I have used IPTRAF command it can capture all the data but when I try to run the script from a local system using vxargs(python), it doesn't work.
2) I have also tried to use IFTOP command but it doesn't save the output to a file.
3) Also /proc/net/dev doesn't work because its captures some extra packets.
Does tcpdump command capture only the number of bytes/packets of the data load transmitted or does the data transmitted will have some headers attached to it?
I would like to capture only data packets from my running network intensive application.
I don't think this can be done trivially. See http://mutrics.iitis.pl/tracedump for a program that seems to accomplish this. However it has not been updated since 2012 and only works on 32 bit arch.
A crude solution could be to run the application through strace and then summarize the return values of the relevant syscalls like write and sendto.
Maybe not what you want, but if you run the process with specified user, let's say appuser, you can add a firewall rule which will count the traffic for you.
example:
iptables -I OUTPUT -m owner --uid-owner appuser -j ACCEPT
check how much packet and bytes sent out by the user:
iptables -vL OUTPUT |sed -n '2p;/appuser/p'
i'm trying to get the TX re-transmission amount for a specific network interface on a Linux 2.6.33.3 kernel.
is there any Linux raw data i can use in order to get/calculate this kind of information?
i've tried netstat, but i couldn't find a way to get the retransmissions value for a specific interface.
with no other "quick" choice, what would it require from me in order to build a small app especially for that? listen to all outgoing packets using any capturing library and count.. what? duplicate packets? by some kind of a packet id?
i'm not a network pro.. am i suppose to find troubles in this kind of mission? (btw, i'll probably try to do it with python. any reason why not to?)
You can check how your interface is configured with the following commands:
mii-tool eth0
ethtool eth0
mii-diag eth0
Not all of them are installed by default in any Linux system, but they are definitely in the distributive and installable.
When you want to measure, how fast is your interface really, you can use dd + netcat:
host1$ cat /dev/zero | nc -l -p 3000
host2$ nc host1 3000 | dd of=/dev/null
^C
dd will write you with which speed was the retransmission between host1 and host2.
If you want per interface, try ifconfig eth0, you probably have what you want there. Just parse it through python.