basildane / WakeOnLAN

Wake On LAN, WakeOnLAN, shutdown software for Windows. A powerful WOL, ping, shutdown, GUI application.
http://wol.aquilatech.com
Other
1.02k stars 147 forks source link

Magic Packet is send on one NIC #206

Open MaciejChalil opened 1 year ago

MaciejChalil commented 1 year ago

We have system with multiple NICs, but WakeOnLAN send Magic Packet only on first NIC. Good feature propably be to select NIC from list to send.

basildane commented 1 year ago

I'm not sure what's wrong here. In https://github.com/basildane/WakeOnLAN/tree/master/WOL/AquilaWOL.vb line 89

We send the WOL packet to every network adaptor. ` For Each adapter As NetworkInterface In nics ' Only display informatin for interfaces that support IPv4. If adapter.Supports(NetworkInterfaceComponent.IPv4) = False Then Continue For End If

            Dim addresses As UnicastIPAddressInformationCollection = adapter.GetIPProperties.UnicastAddresses

            For Each address As UnicastIPAddressInformation In addresses
                If address.Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
                    localEndPoint = New IPEndPoint(IPAddress.Parse(address.Address.ToString()), udpPort)
                    Debug.WriteLine("Interface: " & localEndPoint.ToString())

                    Try
                        client = New UdpClient()
                        client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True)
                        client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, True)
                        client.ExclusiveAddressUse = False
                        client.Client.Bind(localEndPoint)
                        client.Connect(network, udpPort)
                        client.EnableBroadcast = True
                        client.Ttl = ttl

                        client.Send(packet, packet.Length)

                    Catch

                    End Try

                End If
            Next
        Next adapter

`