# indentifying the module a nic uses [SOLVED]

## skizza

Hi all, 

 i have 2 a number wireless cards for playing with  - given that the interfaces for the cards get created when their modules are loaded, i.e.

 wlan0 (using iwl3945), wlan1 (using ath5k) .... is there a way to identify the module that corresponds to each interface progamatically

thanks, izzaLast edited by skizza on Fri May 08, 2009 2:29 am; edited 1 time in total

----------

## paulbiz

lspci -k

----------

## skizza

> lspci -k 

this tells you the kernel module in use, but doesn;t tell you the interface name it is being associated with.  i.e. wlan0 or wlan1

thanks

----------

## albright

how about seeing which goes down with rmmod?

----------

## NeddySeagoon

skizza,

You can read the context sensitive help in the kernel or ask here.

I recall that Debian has a web page that you paste your lspci output into and it tells you which modules you need.

----------

## skizza

albright, thanks,  i initially toyed with that, but it would be too disruptive -- especially if you are using the cards. The solution turns out to be to look at "/sys/class/" ..  anyhow since i was only interested in network interfaces here is my solution.

```

#!/bin/bash 

## look up the module associated with the interface

getDriver() {

    interface=$1    

    if [ -e "/sys/class/net/$1/device/driver" ]

    then

        ## get the driver name 

        module=`ls -l "/sys/class/net/$1/device/driver" | sed 's/^.*\/\([a-zA-Z0-9_-]*\)$/\1/'`

    else       

        printf "ERROR: Nothing registered in /sys/class/net/$1/device/driver\n"      

        module=""

    fi

}

## iterate through the ethernet interfaces

getDrivers() {

    printf "Interface\tModule\n"     

    for interface in `ifconfig -a 2>/dev/null | egrep Ethernet | sed 's/\(Link\)\(.\)*//' | tr -t " " ''`

    do         

        getDriver $interface

        printf "$interface\t -> \t$module\n" 

    done 

}

## do the business 

getDrivers

```

results on my machine :

```

# ~/bin/get-interface-modules 

Interface       Module

eth0       ->     e1000e

wlan0    ->     iwl3945

wlan1    ->     ath5k

```

thanks all for the help,

 izzaLast edited by skizza on Fri May 08, 2009 1:57 am; edited 1 time in total

----------

## albright

that's neat, but surprisingly complex

----------

## skizza

albright, it's not bad, it's just that sadly sed's regexp is by definition fugly  -  to my taste anyhow

----------

## cyrillic

You should also be able to see the module names associated with interface names in /etc/udev/rules.d/70-persistent-net.rules

----------

## skizza

cyrillic: out of curiosity it is better use the udev generated info - or rather what is the advantage.

thanks 

izza

----------

## cyrillic

If you are lazy like me, you would use udev rather than fishing around in /sys for the information.

Udev also allows you to rename interfaces simply by editing that file (if you want to).

----------

