Hack Forums
Detect all network adapters and run commands for each one in bash script? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85)
+---- Thread: Detect all network adapters and run commands for each one in bash script? (/showthread.php?tid=4994244)



Detect all network adapters and run commands for each one in bash script? - Burakku Kenshi - Sep 20, 2015

I have been very busy lately working on scripts for screwing around and i've hit a bit of a wall.
Is there any way to detect EVERY network adapter and for each network adapter found run a specified command? Thanks in advance for any help.


* - XMR - Sep 20, 2015

Here you go, bro:

PHP Code

<?php 
interfaces
=`ls /sys/class/net`
read -a ifacearray <<< $interfaces

for i in "${ifacearray[@]}"
do
      :
      echo 
$i
done 

That script gets all network interfaces, iterates through them all, and prints each of them to console on its own line. The interface name is stored in the $i variable, simply pass it as a command parameter.

Running the script:

Code
root@arccot-kali:~# ./s.sh
eth0
lo
wlan0mon
wlan1



* - Burakku Kenshi - Sep 20, 2015

(Sep 20, 2015 08:51 AM)Arccotangent Wrote:  Here you go, bro:

PHP Code

<?php 
interfaces
=`ls /sys/class/net`
read -a ifacearray <<< $interfaces

for i in "${ifacearray[@]}"
do
      :
      echo 
$i
done 

That script gets all network interfaces, iterates through them all, and prints each of them to console on its own line. The interface name is stored in the $i variable, simply pass it as a command parameter.

Running the script:

Code
root@arccot-kali:~# ./s.sh
eth0
lo
wlan0mon
wlan1

Thank you so much. Thanks to you I finally completed one of my many scripts.
🤗🤗