Sign in to follow this  
Followers 0
sgufa

Select Network Card - show nic IP Adrress

3 posts in this topic

#1 ·  Posted (edited)

I've written this "raw" script in order to select the IP address associated to a Network card.

#include <GUIConstants.au3>

Opt ("GUIOnEventMode", 1)
Opt ("RunErrorsFatal", 0)

If @OSTYPE <> "WIN32_NT" Then
    MsgBox(0, "Invalid Operating System", "This program requires WIndows 2000 or later to run.")
    Exit
EndIf

Dim $ipArray[20]
Dim $nicArray[20]
For $ia = 0 to 19 Step 1
    $ipArray[$ia] = ""
    $nicArray[$ia] = ""
Next
;============================================== Nic Gui ================================================
;shows only active network cards with valid ip address (0.0.0.0 and apipa will not be shown)

$Form1 = GUICreate("Active Network Cards", 276, 79, -1, -1, -1, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_NicClose", $Form1)
GUICtrlCreateLabel("Select IP Address", 58, 8, 157, 17, $SS_CENTER)
$Combo1 = GUICtrlCreateCombo("", 8, 24, 261, 21)
$Button1 = GUICtrlCreateButton("&OK", 123, 56, 30, 20, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent($Button1, "_NicOK")
;===================================================================================================
Func _NicOK()
    GUISwitch($Form1)
    $selNic = StringSplit(GUICtrlRead($Combo1), "[")
    $selIp = StringStripWS($selNic[1], 8)
    GUISetState(@SW_HIDE)
    MsgBox(0, "", $selIp) ; ==> Return $selIp - This may return IP Address
EndFunc

Func _NicClose()
    GUISwitch($Form1)
    $selNic = StringSplit(GUICtrlRead($Combo1), "[")
    $selIp = StringStripWS($selNic[1], 8)
    If $selIp <> '' Then
        GUISetState(@SW_HIDE)
        MsgBox(0, "", $selIp) ; ==> Return $selIp - This may return IP Address
    Else 
        MsgBox(16, "Warning", "Please select IP Address")
    EndIf
EndFunc

;possible start function
RunWait(@ComSpec & " /c " & 'ipconfig >> ' & @TempDir & '\ip.txt', "", @SW_HIDE)
$ipconffile = FileRead(@TempDir & "\ip.txt", FileGetSize(@TempDir & "\ip.txt"))
GUICtrlSetData($Combo1, "")
If $ipconffile = -1 Then
    ;Error!
  Else 
    For $i = 0 to 19 Step 1
        $find = StringInStr( $ipconffile, "IP Address", 1, $i) ; for localized versions you need to change the text between ""
        $nicname = StringInStr( $ipconffile, "Ethernet adapter", 1, $i); for localized versions you need to change the text between ""
        If $find <> 0 And $nicname <> 0 Then 
            $ipAddr = StringLeft(StringTrimLeft($ipconffile, $find+35), 15); for localized versions you need to change the value to add to $find
            $nname = StringSplit(StringTrimRight(StringTrimLeft($ipconffile, $nicname+16), 1), ":")); for localized versions you need to change the value to add to $nicname
            $nicArray[$i] = $nname[1]
            $ipArray[$i] = StringStripWS($ipAddr, 8)
            If StringLeft($ipArray[$i], 1) = "0" Or StringLeft($ipArray[$i], 3) = "169" Then
            Else                
                GUICtrlSetData($Combo1, $ipArray[$i] & " [" & $nicArray[$i] & "]"& "|")
            EndIf
        EndIf
    Next
    FileDelete(@TempDir & "\ip.txt")
EndIf
; end function


GUISwitch($Form1)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg(0)
WEnd

this can be an idea for a possible udf, naturally after optimizing the script.

NOTE: the script works only with english version of windows

If there's a better way to do what this script does, please show me :)

ipselect.au3

Edited by sgufa

Share this post


Link to post
Share on other sites



Cool, might be useful for anonymizing...


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites

thanks! i'd want to know if the script is written in the right way

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0