Перечисление устройств, подключенных в точке доступа через терминал

Я подключаю свою горячую точку через точку доступа и вижу всплывающие уведомления, отображающие подключенное новое устройство , отключенное устройство . (Потому что я хочу узнать о привилегиях для доступа, чтобы использовать или не использовать точку доступа.)

Как я могу перечислить устройство, подключенное через терминал?

16
задан 21 May 2017 в 22:35

5 ответов

arp -a должен возвратить Вас список всех подключенных устройств.

26
ответ дан 21 May 2017 в 22:35

Если Вы хотите более подробный список, я адаптировался этот сценарий к ap-hotspot сценарий, который прибывает из webupd8:

#!/bin/bash

# show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
# written for openwrt 12.09 Attitude Adjustment
# modified by romano@rgtti.com from http://wiki.openwrt.org/doc/faq/faq.wireless#how.to.get.a.list.of.connected.clients

echo    "# All connected wifi devices, with IP address,"
echo    "# hostname (if available), and MAC address."
printf  "# %-20s %-30s %-20s\n" "IP address" "lease name" "MAC address"
leasefile=/var/lib/misc/dnsmasq.leases
# list all wireless network interfaces 
# (for MAC80211 driver; see wiki article for alternative commands)
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
  # for each interface, get mac addresses of connected stations/clients
  maclist=`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`
  # for each mac address in that list...
  for mac in $maclist
  do
    # If a DHCP lease has been given out by dnsmasq,
    # save it.
    ip="UNKN"
    host=""
    ip=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 2 -s -d" "`
    host=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 3 -s -d" "`
    # ... show the mac address:
    printf "  %-20s %-30s %-20s\n" "$ip" "$host" "$mac"
  done
done

копия это в файле в Вашем ПУТИ---, например ~/bin/show_wifi_clients, сделайте его исполняемым файлом с chmod +x и наслаждайтесь.

9
ответ дан 21 May 2017 в 22:35

Покажите список устройств: (замена <interface> с именем интерфейса Вашего интерфейса Wi-Fi)

iw dev <interface> station dump

, Если Вы не знаете название своего интерфейса Wi-Fi, используйте эту команду для обнаружения имени интерфейса:

iw dev
8
ответ дан 21 May 2017 в 22:35

Я подключил свой телефон к сети и использовал потрясающее приложение Fing для сканирования соединенных клиентов :)

https://play.google.com/store/apps/details? id=com.overlook.android.fing& hl=es

https://itunes.apple.com/es/app/fing-esc%C3%A1ner-de-red/id430921107? mt=8

0
ответ дан 21 May 2017 в 22:35

Этот также получает поставщиков Mac устройств и может также маркировать Mac Ваших устройств

требует python3.6

#!/usr/bin/python3.6   
import subprocess
import re
import requests

# Store Mac address of all nodes here
saved = {
    'xx:xx:xx:xx:xx:xx': 'My laptop',
}

# Set wireless interface using ifconfig
interface = "wlp4s0"

mac_regex = re.compile(r'([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}')


def parse_arp():
    arp_out = subprocess.check_output(f'arp -e -i {interface}', shell=True).decode('utf-8')
    if 'no match found' in arp_out:
        return None

    result = []
    for lines in arp_out.strip().split('\n'):
        line = lines.split()
        if interface in line and '(incomplete)' not in line:
            for element in line:
                # If its a mac addr
                if mac_regex.match(element):
                    result.append((line[0], element))
    return result


def get_mac_vendor(devices):
    num = 0
    for device in devices:
        try:
            url = f"http://api.macvendors.com/{device[1]}"
            try:
                vendor = requests.get(url).text
            except Exception as e:
                print(e)
                vendor = None

        except Exception as e:
            print("Error occured while getting mac vendor", e)

        num += 1
        print_device(device, num, vendor)

def print_device(device, num=0, vendor=None):
    device_name = saved[device[1]] if device[1] in saved else 'unrecognised !!'

    print(f'\n{num})', device_name,  '\nVendor:', vendor, '\nMac:', device[1], '\nIP: ',device[0])

if __name__ == '__main__':
    print('Retrieving connected devices ..')

    devices = parse_arp()

    if not devices:
        print('No devices found!')

    else:
        print('Retrieving mac vendors ..')
        try:
            get_mac_vendor(devices)

        except KeyboardInterrupt as e:
            num = 0
            for device in devices:
                num += 1
                print_device(device, num)
0
ответ дан 23 November 2019 в 02:29

Другие вопросы по тегам:

Похожие вопросы: