Menu

#29 Multiply network interfaces

v1.0_(example)
open
nobody
multiply IP (1)
5
2016-04-15
2016-01-12
No

I have 2 active network cards:
1. phisical - DHCP
2. virtual - static
When try to launch XDMCP I've got error below.

Xserver before connect to remote host should detect automatically what interface to use (as you can connect through both depending on target) because DHCP does require to set "from" every time -

Welcome to the VcXsrv X Server
Vendor: The VcXsrv Project
Release: 1.17.5.1

OS: Windows NT 6.1 build 7601 (64-bit)
Contact: marha@users.sourceforge.net

DefineSelf - [myhostname] has 2 usable IPv4 interfaces...
 addresses [1st_IP] [2nd_IP]
DefineSelf - [myhostname] has IPv6 addresses...
 ::1
(EE) 
Fatal server error:
(EE) Multiple ip-addresses detected:
  [2nd_IP]
  [1st_IP]
Please specify the ip-address you want to use with -from
(EE) 
(EE) Server terminated with error (1). Closing log file.

Discussion

  • marha

    marha - 2016-01-14

    You can also specify a hostname with the -from option, it does not have to be the ip-address.

     
  • Roman Koemets

    Roman Koemets - 2016-01-15

    Yes, but no (
    First, most of my linux mashines cannot resolve my/other clients' hostnames.
    Even I hardcode (very very bad habbit) my PC in /etc/hosts of remote linux - it cannot show me xdm.
    Only when I specify exect IP with the -from option everithing works ok.

    xming do not have this issue, but I would prefer to use more modern tool )

     
  • Mar Saint

    Mar Saint - 2016-02-20

    Not sure if this is of use to too many folks. I wrote my own solution to this problem. I use xdmcp over a vpn that uses dhcp, and, like Roman found that vcxsrv balks because it finds two working ipv4 interfaces. It is very impractical to manually change the ip in either a shortcut or by rerunning xlaunch.

    Mostly out of curiosity about powershell, I implemented this as a powershell script. In the end I downloaded PS2EXE from the microsoft technet site, renamed the vcxsrcv executable and put this in as vcxsrve.exe to act as an intermediary. That way you can continue using XLaunch and existing shortcuts, or just make a new shortcut with the parameters you want,

    What it does is to check if this is an xdmcp session (i.e. -query is in the command line), and check if there is a -from in the command line. if -query but not -from, it adds -from with the active ipv4 interface with the lowest metric, since when windows is managing routing it always sets the lowest metric on the current default gateway. If -from is specified but is not an ip, the script looks for an interface with that name. Windows names vpn interfaces with the name you gave them, but in any case, just use the names as they appear in the control panel network interfaces page. So "-from myvpnname" or "-from wi-fi" or "-from 'ethernet 3' (not case sensitive). To the extent of my .. imagination.. this gives a solution to almost every case.

    So, if anyone, particularly the author, is interested, I'm happy to post the script here or wherever you want.

    Oh, out of pure silliness I called it xdinner because it comes after xlaunch ... bad-dum-pum.

     
  • Roman Koemets

    Roman Koemets - 2016-02-24

    Marc Saint,
    Yes, I'm interested to try your script. Please share it any suitable way.
    May be the algorithm will be incorporated in VcXsrv later )

    Thank you in advance

     
  • Mar Saint

    Mar Saint - 2016-02-27

    Here it is. You'll want to paste it into an editor where it won't wrap.

    Sorry for the excessive commenting. I have a terrible memory. In a couple of weeks, it might as well be someone else's code ... but that someone commented it so thoroughly!

        # File Name: XDinner.ps1
        # File Date: 19.2.2016
        # Author: Marie Saint
        # Open Source Software License: MIT
        # 
    
        # Usage: xdinner [<other-args-to-vcxsrv>] [-from <IP address>|<interface name>]
    
        # When an xdmcp connection is specified on a computer that is multi-homed or using a vpn, both XLaunch and
        # vcxsrv will refrain from making any assumptions about which local IP address to use, and give the user
        # no method for solving this other than adding "-from <ip-address>" manually, which is useless if dhcp is used
        # on that connection, since you will have to manually change the address each time you connect.
        #
        # This script is meant to solve that shortcoming in almost all cases. The script acts as an intermediary. The
        # user passes the entire vcxsrv.exe command line (less 'vcxsrv.exe' itself).
        #
        # The best way to use the script is: (1) Download 'PS2EXE' from the Microsoft web site, and use it to convert
        # the script to an exe. If you are using PowerShell 5 (or any version > 4), you need to make a tiny change
        # to the PS2EXE.ps1 file, which has not been updated for PowerShell 5, but works fine with minimal modification.
        # (2) Go to the vcxsrv program directory and rename 'vcxsrvl.exe' to 'vcxsrv.real.exe'. (3) Copy the new exe
        # to the vcxsrv program directory and rename it 'vcxsrv.exe'. 
        # 
        # If you follow the instructions above, you can continue to use XLaunch and any existing shortcuts, and the
        # script will do its job unobtrusively. If you don't like that plan, change the first two lines of code to 
        # assign the the original name of the server program, "vcxsrv.exe", as indicated in the comments below.
        # 
        # Use the script by passing it the same parameters you would pass to vcxsrv.exe, exept that the '-from' option
        # now has additional functionality.
        #
        # The script does the following:
        #           - If neither '-query' nor '-from' are in the command line, this is not an xdmcp connection, and
        #              'vcxsrv.exe' will handle things correctly. In this case, the script does nothing but pass the
        #               parameters on to vcxsrv.exe.
        #           - If '-from' is specified, and it is a valid IP address, the command line is passed 'as is' to
        #               vcxsrv.exe.
        #           - If '-query' is specified, but '-from' is not, the script looks for the active connection with
        #               lowest metric. By default, Windows sets the lowest metric to default gateway, updating
        #               the metric whenever the gateway changes (e.g. a vpn is added). Note that this method fails if
        #               the target is not accessed through the default gateway, e.g. if the local network is accessed
        #               via a different interface than the internet.  This script does not interpret the routing table
        #               to determine how to reach the target. See the next paragraph in this list for solutions in
        #               this case.    
        #           - If '-from' is specified, and it is NOT a valid IP address, the script assumes that the from
        #               parameter is the name of a local interface. In the case of a VPN, the name you gave VPN when
        #               you added it will be the name Windows gives to the interface. In other words, the interface
        #               name will be the name of the of connection as you see it in the Network and Sharing Center,
        #               so just add "-from <my-vpn-name>" to the command line. If the computer is multi-homed, the
        #               interface name is usually something like "Ethernet 2" or just "WiFi". Interface names are not
        #               case sensitive.
        #
    
    ###### (POSSIBLY) TO BE CHANGED BY YOU #########
    # If you don't plan to compile this and put it in the vcxsrv program directory to catch invocations of vcxsrv.exe,
    # then you should un-comment the next line and comment the one after it, i.e. remove the '#' in the next line, add
    # it to the following one.
    # $vcxsrv = "vcxsrv.exe"
    $vcxsrv = "vcxsrv.real.exe"
    ################################################
    
    $addr = $null
    $from = $null
    $fromindex = $null
    $query = ($args -contains "-query")
    $interfaces = get-netipinterface -AddressFamily ipv4 | where {$_.ConnectionState -eq "Connected"} | sort-object -property InterfaceMetric
    
    # Since compiled scripts handle params poorly and vcxsrv.exe has a LOT of options, we'll just deal with searching for '-from'
    for ($i=0; $i -lt ($args.length - 1); $i++) {
        if ($args[$i] -eq "-from") {
            $fromindex = ++$i
            $from = $args[$i]
        }
    }
    
    if ( $from -and [IPAddress]::tryparse($from, [ref]$addr ) ) {
        # If a proper IP Address was included with -from, use that.
        $args[$fromindex] = $addr
    } elseif ( $from ) {
        # If -from is not followed by an IP address, look for an interface (possibly a vpn) named $from.
        $fromInterfaces = $interfaces | where { $_.InterfaceAlias -eq $from }   
        if ( $fromInterfaces ) {
            $args[$fromindex] = [IPAddress] (get-netipaddress -AddressFamily ipv4  -AssociatedIPInterface $fromInterfaces[0]).IPAddress
        }
    } elseif ( $query ) {
        # -from wasn't specified, but this is an xdmcp session (-query was specified). We need to add a -from parameter.
        # Note that when we got interfaces, we already sorted it by metric, and Windows defaults
        # to setting the lowest metric on the default gateway, so the first entry is the one we want.
        $fromindex = $args.length + 1
        $args += "-from"
        $args += [IPAddress] (get-netipaddress -AddressFamily ipv4  -AssociatedIPInterface $interfaces[0]).IPAddress
    }
    if ( !$fromindex -or $args[$fromindex] -is [IPAddress] ) {
        # For clarity: !$fromindex only occurs if this is not an xdmcp session and no -from was specified, in which
        # case we are just passing vcxsrv the args we were given.
        $progdirs = [Environment]::GetFolderPath("ProgramFiles")
        & "$progdirs\vcxsrv\vcxsrv.real.exe" $args
    } else {
        Add-Type -AssemblyName PresentationCore,PresentationFramework
        if ( $from ) {
            [System.Windows.MessageBox]::Show("Could not find a valid IP Address for `"$from`".`nThe `"-from`" parameter must be a valid ip address`nor the name of a vpn or interface.", "Error - local IP not found!",[System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
        } else {
            [System.Windows.MessageBox]::Show("No usable IP local address found.`nIf you see this error but are connected to`nan IP network, well, umm, that's weird.", "Error - local IP not found!",[System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
        }
    }
    
     

    Last edit: Mar Saint 2016-02-27
  • Mar Saint

    Mar Saint - 2016-02-27

    One other thing worth mentioning: you can rename interfaces in network connections settings section of the control panel (you can access this by clicking "Change Adapter Settings" on the left side of the Network and Sharing Center in Win8/10). The name you change it to will be the one you can use with this script.

     
  • Dave Partridge

    Dave Partridge - 2016-03-18

    I totally and wholeheartedly support this feature request. The algorithm used in Mar Saint's script is probably most often what is wanted, though on a truly multi-homed host, it would probably be better to specify that the code should bind to a specific adapter (whose IP may change if using DHCP).

    Choosing the lowest metric adapter would work for all my desktop machines though on one or two servers the ability to specify the adapter to use would be better (but in those cases I can use "from" as their IPs are more normally fixed.

    Here's my current set of adapters on my laptop (ignoring the tunnel adapters) which confused VcXsrv as it chose the VMNet8 adapter to bind to instead of the adapter called "Ethernet" with the result that my Unix box tried to connect back to 192.168.239.1 rather than 192.168.129.83 until I used -from. However if I undock I'll want to use the Wireless port instead of the wired one ...

    Windows IP Configuration

    Host Name . . . . . . . . . . . . : APOLLO
    Primary Dns Suffix . . . . . . . :
    Node Type . . . . . . . . . . . . : Hybrid
    IP Routing Enabled. . . . . . . . : No
    WINS Proxy Enabled. . . . . . . . : No
    DNS Suffix Search List. . . . . . : home

    Wireless LAN adapter WiFi:

    Media State . . . . . . . . . . . : Media disconnected
    Connection-specific DNS Suffix . : home
    Description . . . . . . . . . . . : Broadcom 802.11ac Network Adapter
    Physical Address. . . . . . . . . : B8-EE-65-58-5C-AD
    DHCP Enabled. . . . . . . . . . . : Yes
    Autoconfiguration Enabled . . . . : Yes

    Wireless LAN adapter Local Area Connection* 2:

    Media State . . . . . . . . . . . : Media disconnected
    Connection-specific DNS Suffix . :
    Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
    Physical Address. . . . . . . . . : BA-EE-65-58-5C-AD
    DHCP Enabled. . . . . . . . . . . : Yes
    Autoconfiguration Enabled . . . . : Yes

    Ethernet adapter Ethernet:

    Connection-specific DNS Suffix . : home
    Description . . . . . . . . . . . : Intel(R) Ethernet Connection I217-LM
    Physical Address. . . . . . . . . : EC-F4-BB-56-57-A3
    DHCP Enabled. . . . . . . . . . . : Yes
    Autoconfiguration Enabled . . . . : Yes
    Link-local IPv6 Address . . . . . : fe80::1076:c222:65aa:77f4%13(Preferred)
    IPv4 Address. . . . . . . . . . . : 192.168.129.83(Preferred)
    Subnet Mask . . . . . . . . . . . : 255.255.255.0
    Lease Obtained. . . . . . . . . . : 16 March 2016 21:15:17
    Lease Expires . . . . . . . . . . : 02 April 2016 14:25:01
    Default Gateway . . . . . . . . . : 192.168.129.254
    DHCP Server . . . . . . . . . . . : 192.168.129.254
    DHCPv6 IAID . . . . . . . . . . . : 283964603
    DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1E-1D-9C-69-B8-EE-65-58-5C-AD
    DNS Servers . . . . . . . . . . . : 192.168.129.254
    NetBIOS over Tcpip. . . . . . . . : Enabled

    Ethernet adapter VMware Network Adapter VMnet1:

    Connection-specific DNS Suffix . :
    Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1
    Physical Address. . . . . . . . . : 00-50-56-C0-00-01
    DHCP Enabled. . . . . . . . . . . : No
    Autoconfiguration Enabled . . . . : Yes
    Link-local IPv6 Address . . . . . : fe80::d421:2f47:1909:b763%15(Preferred)
    IPv4 Address. . . . . . . . . . . : 192.168.154.1(Preferred)
    Subnet Mask . . . . . . . . . . . : 255.255.255.0
    Default Gateway . . . . . . . . . :
    DHCPv6 IAID . . . . . . . . . . . : 167792726
    DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1E-1D-9C-69-B8-EE-65-58-5C-AD
    DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
    fec0:0:0:ffff::2%1
    fec0:0:0:ffff::3%1
    NetBIOS over Tcpip. . . . . . . . : Enabled

    Ethernet adapter VMware Network Adapter VMnet8:

    Connection-specific DNS Suffix . :
    Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
    Physical Address. . . . . . . . . : 00-50-56-C0-00-08
    DHCP Enabled. . . . . . . . . . . : No
    Autoconfiguration Enabled . . . . : Yes
    Link-local IPv6 Address . . . . . : fe80::54cf:abbc:c8f9:ff97%6(Preferred)
    IPv4 Address. . . . . . . . . . . : 192.168.239.1(Preferred)
    Subnet Mask . . . . . . . . . . . : 255.255.255.0
    Default Gateway . . . . . . . . . :
    DHCPv6 IAID . . . . . . . . . . . : 385896534
    DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1E-1D-9C-69-B8-EE-65-58-5C-AD
    DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
    fec0:0:0:ffff::2%1
    fec0:0:0:ffff::3%1
    NetBIOS over Tcpip. . . . . . . . : Enabled

    Dave

     
  • Roman Koemets

    Roman Koemets - 2016-04-15

    I cannot reproduce this error on latest version.
    Was issue fixed?
    Or somth wrong with my computer... )

     
  • marha

    marha - 2016-04-15

    Indeed, in the latest version this is not a fatal error anymore, but only a warning message is printed in the log file.

     

Log in to post a comment.