get info from nmcli linux shell script - linux

I am making a script in shell and I want to extract information from the command nmcli.
If I execute nmcli -p dev wifi list in a linux terminal I get a table with all Wi-Fi available. From each Wi-Fi (SSID) in the table I want to get only the SECURITY field.
So the output of the script would be something like:
SSID1 : SSID1-SECURITY
SSID2 : SSID2-SECURITY
... : ...
I've been searching for a while but haven't found how to do it :(
Can someone tell me how to get the security field from each SSID?
Thank you very much.

Don't know much about nmcli, but I think you can do :
nmcli -p dev wifi list | grep 'SSID.*SECURITY'

Related

Read raw USB data for port being used by VirtualBox

I have software for communicating with a serial device that only runs on Windows 7. My host machine is running Ubuntu 16.04, with Windows 7 in virtual box.
I've managed to set it up using USB device filters in VirtualBox settings so that Windows sees and can communicate with the device.
However I'd like to capture what's being sent to and from the device. I thought something as simple as cat /dev/ttyUSB0 would work but unfortunately when I start VirtualBox I get this in dmesg:
[31199.465270] vboxdrv: ffffffffc0df4020 VMMR0.r0
[31199.653494] vboxdrv: ffffffffc0ef7020 VBoxDDR0.r0
[31199.710573] VBoxNetFlt: attached to 'wlp1s0' / 98:54:1b:04:13:48
[31199.863579] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[31199.863674] ftdi_sio 1-3:1.0: device disconnected
So I don't know which file to monitor in /dev anymore. I suppose I might be able to try listen for the communication from Windows, but if I can I'd like to know if it's possible to monitor it from my host machine.
Edit:
This answer helped me for a start. I now get some cool looking stream on the terminal, next step is deciphering it, or if anyone has a better way I'm interested - it looks like the person who answered that question still has deciphering it as a TODO :-)
The fact that it was communicating with software in VirtualBox didn't really matter. This answer got me most of the way just by (as root):
modprobe usbmon
cat /sys/kernel/debug/usb/devices|less and search for device
cat /sys/kernel/debug/usb/usbmon/7u where 7 is the number from "Bus=" in the device table from step 2
From there is was just filtering the output.
A basic way could be just
cat /sys/kernel/debug/usb/usbmon/1u |cut -d\ -f9- | grep ^\n
But the device I was working with was constantly sending lines with just 4 characters, to filter out those I got the address word from the output line, and grepped for that. In my case I only wanted to capture "C" or callback output. I was also filtering for lines that contained more than just the default "0160" that the device was constantly outputting. To try understand the hex output I put a xxd -r -p at the end which gave me:
cat /sys/kernel/debug/usb/usbmon/1u | grep -e 'C Bi:1:005:1\s0\s\w*\s=\s0160\w' | cut -d\ -f8- | xxd -r
Where the grep is
grep -e 'C <address> <someotherstuff> = <always-output-string><anycharacter>
This still gave me this indecipherable junk below, but I don't know the format so I'm stuck here. Maybe the steps to read and filter will be useful for someone
>
O�UDQN��RG_JAMS142E DEFAULT0XXXXXXX�lSTz:�RSDU�vy��������������������������z�fff=�����{6zC"z�u6zC�z�H
;�����C��Af[���RSC�b ISD�EGIN
�CG_IEW0321:0407JUN12S��Z-�$''$'''C'''

wpa_supplicant keeping print message to screen

I am start learning Linux(CentOs 5.5 kernel 2.6.35.13).
When I try to install a usb wifi stick(TP-Link TL-WN823N,and "lsusb" will show ID 0bda:8178 Realtek Semiconductor Corp..)
It work fine in the window interface( ctrl+shift+F7).
But when I shift to the command window(ctrl+shift+F1),and try to start wifi connection by
wpa_supplicant -Bw -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
I found it kept print logs to screen before I type the command above.
I use
ps axjf |grep wpa_supplicant
to list all related process and find
there is a process start by user "dbus" with the command
/usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
I dont know whether is this dbus' command that lead the problem.
Below is the screen shot.
kept logging msg:(
Partly fix the problem.
There are two things that make the wifi information keep on loging on the screen.
First, if you use NetworkManager, it will automate run the command under /etc/sysconfig/wpa_supplicant, where you can find the default command write there has no -B parameter which will keep the log in the background.So you can either add an -B to that command or stop NetworkManager and start wifi connection with your own command like in the question.
Second, when you install the driver, the default run status is power saving mode, so when you transfer data with wifi, you can see the screen keeping log infomation like "get into the pw_saving","get out pw_saving" etc.
To fix this, you can shut down the power saving mode like this:
create a file /etc/modprobe.d/8192cu.conf with the following contents:
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
Or you can rewrite driver code to stop print the info to screen, which I still don't know how to do.

Can't get info from hcidump --raw output

i am trying to create a BLE scan module via nodeJs and Bluez. I want to learn how to get mac address, minor, major and rssi values from the output of hcidump --raw command. I took a look at Radius Networks ibeacon_scan file but i still don't have a clue how i can do it with nodeJs. Can anyone help me with that? Thanks a lot
Try this: sudo hcidump -R -x
Then in a second terminal do your Bluetooth stuff

How to view dmidecode output?

I wanted to use the dmidecode command to retrieve serial information of a remote machine (server). In sites such as this they mention "output", but when I type it into my prompt, it just stays blank. Any help would be appreciated!
# dmidecode -t system
If you're literally typing that into the terminal, nothing is happening because it's considered a comment. What they mean by the # is that it should be run as root. So try: sudo dmidecode -t system.

sending raw data through usb on linux

I'm printing some labels on a Zebra TLP-2844 printer, and have been doing it fine on Windows by sending the EPL instructions to the shared USB printer as follows:
type Label.prn > \my-pc\zebra
and it seems to work with serial ports too, with
type Label.prn > COM1
Now I'm trying to to the same on Linux, but it's getting really hard! My first guess was:
cat Label.prn | /dev/bus/usb/005/002
since my printer is on bus 005, device 002 (checked it with lsusb command) but it doesn't work at all, as I get the following:
bash: /dev/bus/usb/005/002: Permission denied
Any guesses?
The command you did
cat Label.prn | /dev/bus/usb/005/002
will try to run /dev/bus/usb/005/002, which is not executable, hence "permission denied".
The correct command would be, similar to windows
cat Label.prn > /dev/bus/usb/005/002
However, not sure if you actually can write anything to a printer like that in linux. If the printer is set up properly, you might also try:
lpr Label.prn
In case anyone else is trying to access raw USB printer ports; The "permission denied" problem is circumvented by adding your user to group "lp", like so:
$ sudo usermod -aG lp USERNAME
where USERNAME is your username.
Sorry by My english.
I tested here, my printer TLP2844 connect on USB, in my embedded arm9 board with linux.
I typed in command prompt:
printf "OD\r\nN\r\nD5\r\nS2\r\nZT\r\nQ128, 24\r\nq400\r\nA15,10,0,2,1,1,N,\"TESTE\"\r\nP1\r\nFE\r\n" > /dev/lp0
and... the TEST printed
You should change access mode for /dev/usb/lp0 device: sudo chmod a+w /dev/usb/lp0
And then you can print a label using copy command: cp test.zpl /dev/usb/lp0
Also you can create your own build system in Sublime Text for example:
{
"cmd": ["cp", "$file", "/dev/usb/lp0"],
"encoding": "utf8"
}
and send files to the printer by pressing Ctrl+B keys immediately after finishing edit the label.
Or you can try my tool to send zpl labels to the printer via TCP/IP:
https://github.com/kashamalasha/AutoIt_ZebraTester
It was written on AutoIt Script language, so you need to install AutoIt to build it. Unfortunately there is no description on English, only Russian, but I can write it very soon, if you will need it.

Resources