Jump to content
LWC

Auto decide which @IPAddress1-4 to take

Recommended Posts

Posted (edited)

I have multiple network adapters but only one is actually connected.
I thus use @IPAddress1 in my scripts whereas @IPAddress2-4 return 0.0.0.0

But recently I've installed the VirtualBox emulator and it took over @IPAddress1 which means my real connection is now @IPAddress2.
Why is that? Is there a way to make AutoIt skip to @IPAddress2 if @IPAddress1 is used by an emulator?

In the attached screenshot it's temporarily disabled so I can revive my scripts which all already use @IPAddress1.

network adapters.png

 

Update: here's the solution.

Edited by LWC
Linked to solution

Share this post


Link to post
Share on other sites

Try and look around in this post, you may find something useful. I'm not the type of person to deal with these, so I will just supply you with the link and maybe the guide will help you change or possibly explain how it works...

Tell me if you find anything. :)

 

Regards,

Supra

Share this post


Link to post
Share on other sites

If you want the external IP address which is visible to other computers/servers, you can use the _GetIP function:

_GetIP

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
Posted (edited)

TCPNameToIP(@ComputerName)  actually matches @IPAddress1 (the emulated one), so @IPAddress2 (the actual internal one) so it doesn't change anything.

_GetIP() is not relevant as I need the right internal address, not an external one.

So I've ended up successfully using the following code, which finds the first adapter which has a gateway, as seems like emulated ones have no gateways.

But I do wish @IPAddress1-4 would have just given priority to non emulated addresses over emulated ones.

$internal_not_emulated_ip_address=_GetGateway()[0]

Func _GetGateway()
    ; Based on:
    ; Rajesh V R
    ; v 1.0 01 June 2009

       ; use the adapter name as seen in the network connections dialog...
    Const $wbemFlagReturnImmediately = 0x10
    Const $wbemFlagForwardOnly = 0x20
    Local $colNICs="", $NIC, $strQuery, $objWMIService

    $strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration"
    $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
    $colNICs = $objWMIService.ExecQuery($strQuery, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    Local $output[2]

    If IsObj($colNICs) Then
        For $NIC In $colNICs
            if isstring($NIC.DefaultIPGateway(0)) then
                $output[0] = $NIC.IPAddress(0)
                $output[1] = $NIC.DefaultIPGateway(0)
                ExitLoop
            endif
        Next
    Else
        SetError(-1, "No WMI Objects Found for class: Win32_NetworkAdapterConfiguration", "")
    EndIf
    Return $output
EndFunc

 

Edited by LWC

Share this post


Link to post
Share on other sites
Posted (edited)

Did the site I sent at the beginning help in any way? I'm just curious :)

 

Regards,

Supra

Edited by supraaxdd

Share this post


Link to post
Share on other sites
Just now, supraaxdd said:

Did the site I sent at the beginning help in any way? I'm just curious :)

Oh sorry, not really, as it seems to be about internal settings within VirtualBox, which affect the guest virtual machines, not the host.

Share this post


Link to post
Share on other sites

That's all good, as long as you resolved the problem! I'm not into these things, and I just wanted to see if I can help with an article about it...

Good luck in the future!

 

Regards,

Supra

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

  • Similar Content

    • By WoodGrain
      Hi All,
      I'd like to move a window to the top of the stack without it being active.
      I think it's called z-order in programming?
      I've tried these 2 options (commenting out 1 at a time obviously), but the 1st doesn't seem to do anything, and the 2nd prevents it from being moved behind the other programs even after clicking on it and then clicking on another window behind it:
      Local $hWnd = WinGetHandle("[CLASS:MSPaintApp]")
      _WinAPI_SetWindowPos($hWnd, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE))
      _WinAPI_SetWindowPos($hWnd, $HWND_TOPMOST, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE))
      What can I do to move something to the top of the z-order while allowing it to be manually moved back in the z-order?
      Thanks!
    • By AndreyS
      How to make so that the Label control is always on top of all other controls(including pictures and RTF), regardless of their moves, and changes?
      Function GUICtrlSetState($Label, $GUI_ONTOP) does not work.
      Thanks!
    • By GreenCan
      Get some collection of information to help user open a ticket at a 'service desk'

      - User ID: Login Name of User
      - Model: Model of PC
      - Service Tag: Service tag or serial number of the PC (Tested on Dell)
      - Computer Name: Identification of the PC
      - IP Address: All Network adaptors with IP address
      If the adaptor if not currently in use, mentions '(Disabled)' after the IP address
      WLan connection : xxx.xxx.xxx.xxx
      LAN Connection : xxx.xxx.xxx.xxx (Disabled)

      Putclip when done

      ComputerInfo.au3

      GreenCan
    • By jmon
      Hello,

      I am trying to change the z-ordering of controls in my GUI using GUICtrlSetState. How come this example don't work? (I want $LABEL1 to be above $LABEL2)

      #include <GUIConstantsEx.au3> $GUI = GUICreate("Test", 800, 600) GUISetState() $LABEL1 = GUICtrlCreateLabel("under", 20, 20, 500, 300) GUICtrlSetBkColor(-1, 0xFF0000) $LABEL2 = GUICtrlCreateLabel("above", 40, 60, 500, 300) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetState($LABEL1, $GUI_ONTOP) Do Sleep(50) Until GUIGetMsg() = -3 Exit Is there another method to change the z ordering and the order controls receive clicks? I know that the controls should be created in the correct order, but I can't in the script I am doing now.

      Thanks

      [EDIT] Solution is in post #5
    • By GordonFreeman
      The values are:
      eg.

      10 - 6 - 56 - 37 - 21

      And i need transform the array in:

      6 - 10 - 21 - 37 - 56

      I try but return:

      10 - 21 - 37 - 56 - 6

      Note: I need the ascending.

      That is, 6 can not be greater than 56
×
×
  • Create New...