获取活动网络接口
Author: Dimitrios Anogiatis
此功能将为你提供活动的网络接口(即eth0或wlan0等)
它可以用于shell函数或任何依赖于此信息的内部函数
PUBLIC FUNCTION getActiveNetworkInterface() AS String
DIM tmpNIF AS String[]
DIM tmpActive, tmpString AS String
DIM iterator AS Integer
DIM tmpFile AS File
'get the interface directories
tmpNIF = Dir("/sys/class/net")
'check each folder's oper file to see if the interface is up and running
FOR iterator = 0 TO tmpNIF.Count - 1
tmpString = "/sys/class/net" &/ tmpNIF [iterator]&/ "operstate"
'check the operational state of each interface
tmpFile = OPEN tmpString FOR INPUT
WHILE NOT Eof(tmpFile)
LINE INPUT #tmpFile, tmpActive
WEND
CLOSE #tmpFile
'if it's reported as up then return it's name
IF tmpActive = "up" THEN RETURN tmpNIF[iterator]
NEXT
END