Skip to content

Commit

Permalink
v6.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel (Fourdee) committed Aug 20, 2018
1 parent 3a72dee commit fee1d2b
Showing 1 changed file with 49 additions and 37 deletions.
86 changes: 49 additions & 37 deletions dietpi/func/obtain_network_details
Original file line number Diff line number Diff line change
Expand Up @@ -39,72 +39,84 @@

ETH_INDEX=0
WLAN_INDEX=0

ACTIVE_DEVICE='NULL'
ETH_IP=''
WLAN_IP=''
IP_ADDRESS='Use dietpi-config to setup a connection'

#/////////////////////////////////////////////////////////////////////////////////////
# Main Loop
#/////////////////////////////////////////////////////////////////////////////////////
DEV_MAX=9
Scrape_IP(){

#ETH
for (( i=0; i<=$DEV_MAX; i++ ))
do

ETH_IP=$(ip -o a s eth$i 2>/dev/null)
if (( $? == 0 )); then

#grab content of ip l
ip -o l > $FP_TEMP
ETH_INDEX=$i
ETH_IP=${ETH_IP#*inet* }
ETH_IP=${ETH_IP%%/*}

# Find active eth device
if tmp=$(grep -m1 ' eth[0-9]: .* state UP ' $FP_TEMP); then
if [[ -n $ETH_IP ]]; then

tmp=${tmp#* eth}
ETH_INDEX=${tmp%%: *}
ACTIVE_DEVICE='eth'$ETH_INDEX
IP_ADDRESS=$ETH_IP
break

ACTIVE_DEVICE="eth$ETH_INDEX"
IP_ADDRESS=$(ip -o a s $ACTIVE_DEVICE)
IP_ADDRESS=${IP_ADDRESS#*inet* }
IP_ADDRESS=${IP_ADDRESS%%/*}
fi

# Else find available eth device
elif tmp=$(grep -m1 ' eth[0-9]: ' $FP_TEMP); then
fi

tmp=${tmp#* eth}
ETH_INDEX=${tmp%%: *}
done

fi
#WLAN
for (( i=0; i<=$DEV_MAX; i++ ))
do

# Find active wlan device
if tmp=$(grep -m1 ' wlan[0-9]: .* state UP ' $FP_TEMP); then
WLAN_IP=$(ip -o a s wlan$i 2>/dev/null)
if (( $? == 0 )); then

tmp=${tmp#* wlan}
WLAN_INDEX=${tmp%%: *}
echo yes

# Eth has priority
if [[ $ACTIVE_DEVICE == 'NULL' ]]; then
WLAN_INDEX=$i
WLAN_IP=${WLAN_IP#*inet* }
WLAN_IP=${WLAN_IP%%/*}

ACTIVE_DEVICE="wlan$WLAN_INDEX"
IP_ADDRESS=$(ip -o a s $ACTIVE_DEVICE)
IP_ADDRESS=${IP_ADDRESS#*inet* }
IP_ADDRESS=${IP_ADDRESS%%/*}
if [[ $WLAN_IP && ! $ETH_IP ]]; then

fi
ACTIVE_DEVICE="wlan$WLAN_INDEX"
IP_ADDRESS=$WLAN_IP
break

# Else find available wlan device
elif tmp=$(grep -m1 ' wlan[0-9]: ' $FP_TEMP); then
fi

tmp=${tmp#* wlan}
WLAN_INDEX=${tmp%%: *}
fi

fi
done



}

#/////////////////////////////////////////////////////////////////////////////////////
# Main Loop
#/////////////////////////////////////////////////////////////////////////////////////
Scrape_IP
#-----------------------------------------------------------------------------------
#Output to file
cat << _EOF_ > $FP_NETFILE
$ETH_INDEX
$WLAN_INDEX
$ACTIVE_DEVICE
$IP_ADDRESS
ETH_IP=$ETH_IP
WLAN_IP=$WLAN_IP
_EOF_
# Assure that non-root user can call this script:
# Assure that non-root user can read file:
chmod 666 $FP_NETFILE &> /dev/null

#Clean up tmp files used
rm $FP_TEMP
#-----------------------------------------------------------------------------------
exit
#-----------------------------------------------------------------------------------
Expand Down

0 comments on commit fee1d2b

Please sign in to comment.