Linux get device name

How to get device name from scan like nmap on Linux

I know that I can use a tool like NMAP or arp-scan on Linux to identify the IP and MAC addresses of all devices on my local network. I also know that arp-scan will do a MAC address lookup to get the device manufacturer. But is there any set of options on these commands (or any other command) that can tell me the actual device name of the device at a give IP? For example, if «Joe’s iPad» is on 192.168.1.113 I want a command to get that name.

@Marc Doesn’t your nmap -v -sP 192.168.1.0/24 | grep up. give you host-names? Mine for example gives Host XPS8500.fritz.box (192.168.1.33) appears to be up. .

if you know the dns server you can try nmap -A -v —dns-servers 10.10.10.10 10.20.20.20 where 10.10.10.10 is the dns server and 10.20.20.20 is the target

2 Answers 2

Nmap

Some hosts could simply be configured to not share that information. It should work just like this:

user@host:~$ nmap 192.168.1.113 Starting Nmap 7.00 ( https://nmap.org ) at 2015-12-11 08:45 AWST Nmap scan report for Joes iPad (192.168.1.113) Host is up (0.0038s latency). Not shown: 999 closed ports PORT STATE SERVICE 62078/tcp open iphone-sync Nmap done: 1 IP address (1 host up) scanned in 41.88 seconds 

You can force Nmap to attempt reverse DNS resolution for all targets, by using the following option:

-R (DNS resolution for all targets). Tells Nmap to always do reverse DNS resolution on the target IP addresses. Normally reverse DNS is only performed against responsive (online) hosts. 

This might help in some cases. The output will look more or less identical:

user@host:~$ nmap -R 192.168.1.113 Starting Nmap 7.00 ( https://nmap.org ) at 2015-12-11 08:46 AWST Nmap scan report for joes-ipad.local (192.168.1.113) Host is up (0.0047s latency). rDNS record for 192.168.1.113: joes-ipad.local Not shown: 999 closed ports PORT STATE SERVICE 62078/tcp open iphone-sync Nmap done: 1 IP address (1 host up) scanned in 42.61 seconds 

Either way; you can always parse the output through external tools, such as grep . This can be particularly useful if you’re scanning several addresses, or even whole network ranges at a time:

user@host:~$ nmap 192.168.1.0/24 | grep '(192.168.1.113)' Nmap scan report for Joes iPad (192.168.1.113) All 1000 scanned ports on Joes iPad (192.168.1.113) are closed 
user@host:~$ nmap -R 192.168.1.0/24 | grep '(192.168.1.113)' Nmap scan report for Joes iPad (192.168.1.113) All 1000 scanned ports on Joes iPad (192.168.1.133) are closed 

Net-Tools

What you (probably) actually want to do, is this:
*Output will vary, based on OS & software version.

user@gnu:~$ arp 192.168.1.113 Address HWtype HWaddress Flags Mask Iface Joes iPad ether a1:b2:c3:d4:e5:f6 C wlan0 
user@bsd:~$ arp 192.168.1.113 Joes iPad (192.168.1.113) at a1:b2:c3:d4:e5:f6 on en0 ifscope [ethernet] 

Источник

Читайте также:  Segfault error in linux

Shell how to get device name in lsusb

You may want to use flags to have output printed like this: and then over the input to filter out those lines with usb at the beginning of the line. So you print any field you want, here are the mapping: $1 : Bus $2 : 001 $3 : Device $4 : 004: $5 : ID $6 : 0665:5161 $7 : Cypress $8 : Semiconductor $9 : USB $10 : to $11 :

How to get device filename from lsusb output or by device path

Supposing I’m trying to find the device for my UVC camera, lsusb gives me:

Bus 001 Device 004: ID 1e4e:0102 Cubeternet GL-UPC822 UVC WebCam 

The device filename is then /dev/bus/usb/001/004 (first component is bus id, next is device id).

I’ve just built a script for that, it’s not pretty but works for me.

I tested this script on Arch Linux with this configurations:

$ uname -a Linux 4.4.13-1-lts #1 SMP Wed Jun 8 16:44:31 CEST 2016 x86_64 GNU/Linux 

And my device name is /dev/sdb which is quite different from yours, I hope it will work for you as well.

Also note that this script depends on usbutils package for usb-devices program, I believe its installed by default on all linux, but i might be wrong.

#!/usr/bin/bash # Input should be a single line from lsusb output: DATA=$1 # Read the bus number: BUS=`echo $DATA | grep -Po 'Bus 0*\K2+'` # Read the device number: DEV=`echo $DATA | grep -Po 'Device 0*\K7+'` FOUND=false USB_Serial="" # Search for the serial number of the PenDrive: while read line do if [ $FOUND == true ]; then USB_Serial=`echo "$line" | grep -Po 'SerialNumber=\K.*'` if [ "$USB_Serial" != "" ]; then break; fi fi if [ "`echo "$line" | grep -e "Bus=0*$BUS.*Dev#= *$DEV"`" != "" ]; then FOUND=true fi done  
$ ./usbname "$(lsusb | grep '')" /dev/sdb 

I use this small bash function

getdevice() < idV=$idP=$ for path in `find /sys/ -name idVendor | rev | cut -d/ -f 2- | rev`; do if grep -q $idV $path/idVendor; then if grep -q $idP $path/idProduct; then find $path -name 'device' | rev | cut -d / -f 2 | rev fi fi done > 
# lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 005: ID 8087:0a2b Intel Corp. Bus 001 Device 012: ID 0bda:2832 Realtek Semiconductor Corp. RTL2832U DVB-T Bus 001 Device 053: ID 051d:0002 American Power Conversion Uninterruptible Power Supply Bus 001 Device 051: ID 1cf1:0030 Dresden Elektronik Bus 001 Device 006: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter Bus 001 Device 004: ID 05e3:0606 Genesys Logic, Inc. USB 2.0 Hub / D-Link DUB-H4 USB 2.0 Hub Bus 001 Device 003: ID 0658:0200 Sigma Designs, Inc. Aeotec Z-Stick Gen5 (ZW090) - UZB Bus 001 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode) Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

and corresponding devices

# getdevice 051d:0002 hiddev0 hidraw0 # getdevice 1a86:7523 ttyUSB0 # getdevice 0658:0200 ttyACM1 

Android Device not recognized by adb, Generally, I think your USB connection should be set to use MTP (Media Transfer), however, I couldn't get my computer to recognize my device (Nexus 4).

Get the device name of connected USB disk

You can do it with lsblk command.

NAME TRAN sda sata sda1 sdb usb sdc usb sr0 sata 

-l stands for "list" format, so it's easier to parse. Otherwise, you would get a tree format like this:

NAME TRAN sda sata └─sda1 sdb usb sr0 sata 

Specifying other flags will give you more information like FSTYPE, LABEL, UUID, MOUNTPOINT and many other, just run lsblk --help to see all options.

You may want to use --paths --noheadings --scsi flags to have output printed like this:

sata /dev/sda usb /dev/sdb usb /dev/sdc sata /dev/sr0 

and then grep over the input to filter out those lines with usb at the beginning of the line.

Do lsusb , it gives the name of the devices connected via the USB bus.

$ lsusb Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 0421:0802 Nokia Mobile Phones CA-42 Phone Parent Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

Description

lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.

SerialPort not detected on Linux but on Windows, How can i setup my system that Linux detect the device as a Serial Interface to collect the data from the Serial Port. The goal is that a python

Linux shell get device id from user input

The first errors that I see are. You wrote $usblist=(lsusb | awk '')

You need to remove the $ from the start, and add a $ before the ( . Some quotes will also help. i.e.

Just use, this uses awk to print out the 6th field which in your case is the ID of the device

So you print any field you want, here are the mapping:

  • $1 : Bus
  • $2 : 001
  • $3 : Device
  • $4 : 004:
  • $5 : ID
  • $6 : 0665:5161
  • $7 : Cypress
  • $8 : Semiconductor
  • $9 : USB
  • $10 : to
  • $11 : Serial

If you want to print more than one field , such as name , you can do like this

Array assignment syntax in zsh, ksh93, bash, mksh or yash is:

Getting the output of a command is $(a command) .

Splitting the output of a command on newline can be done with the f parameter expansion flag in zsh or in other shells by leaving that $(. ) unquoted (the split+glob operator), after having assigned the newline character to the $IFS special variable and disabled globbing.

IFS=' ' set -o noglob # not needed in zsh unless in sh/ksh emulation array=( $(a command) ) 

To get the 6 th blank delimited field of each of the lines of the output of a command, as others have said, you can use awk '' . So putting it altogether, that becomes:

IFS=' ' set -o noglob array=( $(lsusb | awk '') ) 

Now, the default value of $IFS is space, tab, newline (and NUL in zsh), and USB ids in theory only contain hexadecimal digits and colons, so the output of awk should be guaranteed not to contain space, tab, nul nor glob characters, so if you can guarantee that $IFS still contains its default value, you can omit the first two commands and simplify it to:

Or you could get the information directly from /sys without need for the lsusb nor awk command in zsh with:

array=( /sys/bus/usb/devices/*/idVendor(Ne['REPLY=$(<$REPLY):$(<$REPLY:h/idProduct)']) ) 

Using globbing to find the idVendor files and the e glob qualifier to replace each glob expansion with the contents of that file and that of the idProduct file in the same directory (also has the benefit of giving you a sorted list).

Linux equivalent of Windows Device Manager / DevCon utility?, lspci , lsusb , lsscsi , and lscpu are also very helpful. Most busses such as PCI, SCSI, USB, have a lot of userland utilities available in most

Источник

How to find the Absolute device name

Using the path discovered in the previous question, look at this path in the /dev directory using a long listing ls command. Assuming this is in fact a soft link, what is the absolute device name which this link is pointing to?

  • ls - list files in the file system.
  • lsblk - list the block devices (i.e. drives)
  • lspci - list the pci devices.
  • lsusb - list the USB devices.
  • lsdev - list all the devices.

4 Answers 4

"absolute device name" is not a term that is in common use as far as I know.

Maybe they mean an absolute path to a block device file that corresponds to the LVM logical volume.

Or given that they mention "soft link", which itself is more commonly referred to as "symbolic link" or "symlink", maybe they meant the absolute canonical (i.e. free or any symlink, . and .. components and with only one / in between each component and at the start and none at the end) path to a device file for that LV.

/dev/VG_name/LV_name is generally an absolute path to the LV_name LV in the VG_name volume group. /dev/mapper/VG_name-LV_name is often another one path to the same device file (though note that - in the VG/LV names are encoded as -- ).

Running readlink -e on both should give you the canonical absolute path of that file (generally something like /dev/dm- ).

Now, you do cp -a /dev/dm- /root/mydevice , and /root/mydevice will be another canonical absolute path to a block device file for that LV.

$ ls -l /root/mydevice brw-rw---- 1 root disk 253, 1 Sep 15 06:17 /dev/dm-1 

What identifies the device here are the b (type: block), 253 (major number) and 1 (minor number) above that identify the device. You can recreate the same with the mknod command.

On Linux, to find the canonical name for that block device, you can look for 253:1 in /sys/class/block/*/dev :

$ grep -xFl 253:1 /sys/class/block/*/dev /sys/class/block/dm-1/dev 

Or resolve the /sys/dev/block/253:1 symlink:

$ readlink -e /sys/dev/block/253:1 /sys/devices/virtual/block/dm-1 

dm-1 being the canonical name here. udev would generally create a corresponding /dev/dm-1 file when that device is discovered.

Источник

Оцените статью
Adblock
detector