LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2016, 10:13 PM   #1
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Rep: Reputation: 20
Question Distinguishing different network device types in a shell script


I'm trying to find a way to check, from a shell script, what type of device each of the system's network devices is. I'm using Xubuntu 16.04.1.

Looking through '/sys/class/net/', I've noticed that wireless devices have a 'wireless' subdirectory, eg. '/sys/class/net/wlp3s0/wireless', and a 'uevent' file containing the line 'DEVTYPE=wlan'. Are these reliable properties for determining that a device is a wireless network device?

Is there anything that indicates an ethernet device, or is it only inferred by the lack of other indicators such as the 'wireless' indicators? There is no ethernet equivalent to the 'wireless' subdirectory and 'wlan' value. Are there any other flags that definitively indicate an ethernet device?
 
Old 10-19-2016, 06:40 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,679

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
With predictable naming the first two characters indicate the type of device. wl is wireless and en is a PCI ethernet adapter.

https://blog.laimbock.com/2014/11/22...omment-page-1/
https://www.freedesktop.org/wiki/Sof...nterfaceNames/
 
Old 10-19-2016, 04:02 PM   #3
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by michaelk View Post
With predictable naming the first two characters indicate the type of device. wl is wireless and en is a PCI ethernet adapter.
Thanks for the response. Unfortunately it seems it doesn't always work that way, so I was hoping to find a hardware-dependent flag of some kind to indicate an ethernet interface.

On my desktop pc the ethernet nic (on the motherboard, not in a pci slot, btw) is named 'p3p1'; the command 'journalctl -b | grep eth0' shows this:
Code:
alx 0000:05:00.0 eth0: Qualcomm Atheros AR816x/AR817x Ethernet [74:d4:35:ea:07:41]
alx 0000:05:00.0 p3p1: renamed from eth0
On my laptop the the ethernet nic is 'enp2s0', and the same command shows:
Code:
r8169 0000:02:00.0 eth0: RTL8168e/8111e at 0xffffad1980018000, b8:70:f4:bf:b2:38, XID 0c200000 IRQ 33
r8169 0000:02:00.0 enp2s0: renamed from eth0

Last edited by genogebot; 10-19-2016 at 04:07 PM.
 
Old 10-19-2016, 04:20 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,679

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
The laptop adapter is on the motherboard whereas the desktop is a PCI device I would guess. I don't know if there is an independent flag.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script to transfer files, renaming duplicates from a portable device. Rudifn2007 Linux - Newbie 10 11-10-2015 10:04 AM
[SOLVED] Shell script to table RAW device values kayasaman Programming 8 04-04-2011 01:34 AM
Running a script when a network device becomes up or down Jouxte Linux - Networking 1 09-27-2009 10:10 PM
[SOLVED] Detect a CD-ROM device in a bash shell script kushalkoolwal Programming 3 08-21-2009 05:41 PM
Retrieving mime types in shell script haydenyoung Programming 5 03-21-2007 10:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration