How to use iwlist to scan hidden ssid? - linux

Should I configure some wireless settings (use commands on linux) so that "iwlist wlan0 scan" can list hidden APs if they exist? Or iwlist always reports hidden APs?
(I don't want to use wpa_supplicant to do AP scanning.)

Commenting on a pretty old post but just came across this question and I don't believe iwlist scans for hidden APs. Remember the AP name is not broadcasted at all so there is no way for iwlist to magically find the name.
Instead, you have to pass the name of the AP during your scan. I.e you have to actively probe for that hidden network.
So your command should look something like this:
iwlist <my_wireless_interface> scan essid <my_fancy_essid>
Although I don't know how to scan for multiple hidden essids in a single scan, this should detect a single hidden SSID.
I have to mention this -- Hidden SSID does NOT add security at all.

I think iwlist will show hidden non broadcasted SSIDs as well.
But to be sure you can test that by hiding your AP's SSID and test it (best way to be sure).

iwlist <you_interface_name> scanning essid <your_hiddden_ssid>
will do the trick
otherwise iwlist shows hidden ssids with empty ESSID
e.g.: ESSID:""
than you have to match by the Address-Field, which holds the MAC
of the Station/Router.

Related

How to make Linux ignore a keyboard while keeping it available for my program to read?

I am building some kind of kiosk system and I bought this USB DIY keyboard for it: https://www.amazon.com/gp/product/B07QPXQQ7L
This allows me to have a lot of buttons and they behave like keyboard keys.
I'm writing a program (Perl) that will take the input from that keyboard and do things based on that.
The problem is that I need to have the rest of the system (both X and the TTYs) ignore that keyboard so that it won't type random things in the terminal or in the window manager. In other words, the system should disregard it but the device itself must still be available in /dev/input/...
I don't need a real keyboard to control the machine because I connect via VNC and SSH.
Bonus points if you know how to read from a /dev/input/... keyboard and end up with letters typed just like with STDIN in a terminal.
Thanks!
I found the solution here where someone wanted the exact same thing in the case of a barcode reader:
https://serverfault.com/questions/385260/bind-usb-keyboard-exclusively-to-specific-application/976557#976557
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", RUN+="/bin/sh -c 'echo remove > /sys$env{DEVPATH}/uevent'"
ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", SYMLINK+="diykeyboard"
And then replace xxxx and yyyy by the Vendor and Product ID as found in lsusb. So in my case 1c4f and 0002:
Bus 001 Device 003: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
The udevadm control --reload thing didn't do it for me, I had to reboot.
Then in theory the data typed on the keyboard should be available at /dev/diykeyboard (the SYMLINK variable).
Now in my case unfortunately there are multiple events that match this vendor+product, and to match the right one I needed to add DEVPATH=="*:1.0/*", KERNEL=="event*" in the second line where it creates the SYMLINK. And then surprise it did not create the link in /dev so I had to do something dirty, create a link myself with ln:
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="1c4f", ATTRS{idProduct}=="0002", RUN+="/bin/sh -c 'echo remove > /sys$env{DEVPATH}/uevent'"
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="1c4f", ATTRS{idProduct}=="0002", DEVPATH=="*:1.0/*", KERNEL=="event*", RUN+="/bin/sh -c 'ln -sf /dev/input/$kernel /diykeyboard'"
(don't create the link in /tmp since udev happens before the mounting of /tmp at boot)
From there I can read from /diykeyboard (which usually points to /dev/input/event0) either with evtest which shows the keys typed, or directly with my program and then decoding the scancodes.

Obtain RSSI from bluetooth adapter Raspberry3

I need to know how I can obtain de REAL RSSI from a non-connected bluetooth device with my RPi3.
I know there is a program named bluetoothctl which I don't know how it works, I can't find anything about how it works bluetootctl. But when I used it, I can obtain ALL the REAL RSSI of ALL the bluetooth devices, only with a scanning. (scan on)
I do this.
1) bluetoothctl
2) scan on
(you will obtain something like this: "Device XX:XX:XX:XX:XX:XX RSSI: -48" )
It's so simple, but, the problem, it's that I need to work with this data, I am not able to get this data to process later. So I need some code, in c++(better) to do this.
I know hcitool, but you have to be connected and they not give you data until you are at a distance. I can't understand how it works bluetoothctl
I try to do a redirect of the output to a log but...I am not able to do that..because when you put on temrinal bluetoothctl it happens this:
pi#raspberrypi:~ $ bluetoothctl
[NEW] Controller B8:27:EB:90:E8:79 raspberrypi [default]
[bluetooth]#
now, you can use all the commands of bluetoothctl
Thanks ;)
Look at source as kaylum said.
You will find in doc folder hci and dbus documentation.
You can also take the bluetoothctl source (available in the folder client) and make a wrapper around it to your needs. It uses the dbus library helper developed in gdbus folder.
you can see the rssi value using hcidump [-a] command but make sure to keep Bluetooth on in background , so u can just start scanning like you usually do in Bluetoothctl and then Scan on ,leave that in background and on a new command line use the hcidump command This might help you.See this also : http://www.linuxcommand.org/man_pages/hcidump8.html
You can use the following, from the command line
sudo btmon |grep RSSI &
sudo hcitool scan
Or if you want to use python you can use the inquiry with rssi example found in the pybluez module.
Another option would be to use the DeviceDiscoverer skeleton class found in this example and then adjust to your own needs. The device discovered function is passed the rssi which can be stored and manipulated to suit.

Using different console for respawn process in inittab on embedded device

I am connected on my embedded device with the serial port and would like to start my custom binaries on boot and be able to see the output generated.
My /etc/inittab file contains:
console::respawn:/sbin/getty -L 115200 ttyAPP3 vt100
console::respawn:/usr/bin/mybinary
With this configuration, I can see the output of mybinary in the serial console but It is difficult/impossible to connect (insert login and password) to getty because of the interference of the output generated.
I tried to switch the output in inittab to another not used tty (tty10) like this:
console::respawn:/sbin/getty -L 115200 ttyAPP3 vt100
tty10::respawn:/usr/bin/mybinary
And now I can connect but how can I see the output generated to /dev/tty10 ?
I tried cat /dev/tty10 but nothing is shown.
I know the question is old, but it has no answers at all for crying out loud.
Remember that a TTY is both an output device and also an input device -- by cat'ing from it you're reading input from the terminal which means the keyboard, NOT the screen.
I don't know if there's a parallel in other *nixes, but Linux systems have /dev/vcsX and /dev/vcsaX character devices (nodes c,7,0+X and c,7,128+X respectively) for each /dev/ttyX device - these are mirrors of the data currently on the output of the TTY device (ie. the screen part of the TTY, not the keyboard part). These will give you what you're looking for. The vcsaX devices will give you a displaybyte+attributebyte pair (i.e. the foreground/background text colour -- see other references for more information on text attribute bytes) for each character on the screen, while the vcsX devices give only the displaybyte for each character. Of course it's a raw stream/dump so if the row and/or column count of your terminal doesn't match that of the the TTY you're dumping then you'll need to parse the data and reformat it to match.
tl;dr: use "cat /dev/vcs10"
Hope that helps.

Can't send AT commands to Bluetooth module with UART interface

I want to change the pairing code of a device. It's a chinese clone of a MiniELM327 adapter with a Bluetooth interface. If I power it up through its OBD2 connector supplying 12V, the whole device is on. Through the Bluetooth Serial Port I can communicate with the ELM327 chip and send AT Commands, receiving correct answers.
But that is not what I want to do. I want to change the pairing code of the bluetooth interface itself.
The module is a RG-BT10-10 from Redgoo based on a Beken BK3211 chip. I have the datasheet and the command set (not sure if it's the right one). Unfortunately it is all in chinese and the customer support is in chinese too (they use automatic translators).
www . redgoo.com.cn/product/20131106105822750.pdf
www . redgoo.com.cn/product/20131130122844243.pdf
www . belon.cn/Uploadfiles/psd/BK3211datasheetv1.2.pdf
I tried to contact the manufacturer and they said that I have to send the following commands:
AT+EN1 (enter command mode)
AT+PIN****
AT+EN0 (exit command mode)
and then reset the module.
I bought a ftdi-based USB-to-UART converter at denkovi.com
www . denkovi.com/usb-to-uart-ftdi-serial-interface-adaptor
Then I wired the pins on the USB-to-UART with the corresponding contacts on the RG-BT10-10 (Tx and Rx are switched of course).
According to the datasheets, the parameters are:
Baud Rate: 38400
Parity: None
Data bits: 8
Stop bit: 1
And the AT commands should be terminated with \r\n that is CR+LF if I'm not mistaken.
No information on flow control. The RTS pin on the board is not even soldered, meaning that it's not used during device normal operation.
From here on, I'm lost. I tried with several programs (Hyperterminal, Putty, Tera Term etc.) to send the AT command which should yield an "OK" but no response has ever arrived.
To be clear, if I fiddle with the wires (like grounding and releasing RTS or turning the RG-BT10-10 on and off) I sometimes get some chars so the flow of data from the module to the computer physically works.
Is there some basic theory I'm missing? I can't get enough information from the manufacturer (language barriers...). And I believe that I have all the hardware that I need, so I just have to understand how to set it correctly :)
Thank you very much for your help!
I had exactly your problem. No response to AT from PuTTY or HyperTerminal at 9600 Baud (which is correct/default for the SPP-CA).
All I would see is:
+READY
+PAIRABLE
when powering up.
I then tried the Serial Monitor that comes with the Arduino IDE, www .arduino.cc/download_handler.php?f=/arduino-1.6.7-windows.exe. Changed line endings to "Both NL & CR" and at 9600 Baud, it came to life:
AT
OK
AT+VERSION
+VERSION=+BOLUTEK Firmware V2.2, Bluetooth V2.1
I hope this helps someone.
You can also use Putty to send
Ctrl+M : Carriage Return(“\r”)
Ctrl+J : Line Feed(“\n”)
This worked for me in getting a response:
AT [CTRL-J]
OK

Ubuntu: wait for network link up and execute a bash command

In Ubuntu (the latest distro is fine), I want to reboot a router and inside a bash script I'd like to have a command that waits for the network link to be up again and, when it detects that, it has to start a bash command.
I could implement this with some kind of polling loop, but the ideal solution would be to have a bash command that, when executed, waits for the link to be up and automatically executes a bash command that I gave to it.
I read something about dbus (and dbus seems the way to go) but it also seems that it takes too much time to fully understand how to use it properly. I was suggested to check if a tool like ethtool was able to do that kind of "wait and execute" but in the man pages I didn't find anything about it.
Note: I forgot to say that I'd like the command to check if the PHYSICAL layer of the link is up. So solutions working at upper layers are not accepted. Moreover, solutions involving putting scripts inside directories (such as/etc/network/if-up.d) are not accepted too.
Any ideas?
Thank you
The event listener I suggested:
inotifywait -e modify /sys/class/net/eth0/carrier; echo 'Change detected'
When you plug or unplug network cable, it will trigger echo 'Change detected', of course it could trigger just about anything.
And this will run as one off, but I take you know how to make a daemon out of it, if not it will be a good exercise to learn :)
If you want a command to check if the link is up or down use ip :
ip addr show eth0 | grep -Po "(?<=state ).*?(?=\s)"
DOWN
ip addr show wlan0 | grep -Po "(?<=state ).*?(?=\s)"
UP
You can check link is up/down by /sys/class/net/eth0/carrier file
cat /sys/class/net/eth0/carrier
if output is 1 then ethernet cable is plugged in and link is up.
if output is 0 then ethernet cable is removed and link is down.
Note:if you have interface other then eth0 then replace interface like eth2/eth3 in place of eth0

Resources