remcohaszing / pywakeonlan

A small python module for wake on lan.
https://pywakeonlan.readthedocs.io
MIT License
281 stars 68 forks source link

Update wakeonlan.py #10

Closed mrtnRitter closed 2 years ago

mrtnRitter commented 4 years ago

Added interface for use on computers with multiple nics. Default interface is set up dynamically.

Usage example: send_magic_packet(mac, interface=someipadress)

Trinity503 commented 4 years ago

Hello Moritz,

thank you for the interface-option. It works great. But, is there a possibility to send the magic-packet through all interfaces by default? Thanks! Markus

mrtnRitter commented 4 years ago

Hi Markus,

if the target is connected with all interfaces, it's enough to send the package through one of the interfaces. If there a several targets on several interfaces, you can call the script several times with different IPs and interfaces. What is you exact use-case?

*Martin

Trinity503 commented 4 years ago

Hello Moritz,

thanks for your reply!

This is my setup:

Server with two interfaces:

Interface1: 192.168.2.2 (255.255.255.0)

Interface2: 192.168.3.2 (255.255.255.0)

From this server I want to wake up clients in both nets. With the standard „wakeonlan“ in python, I can only wake up clients in the first IP-range.

With your version of wakeonlan, i call:

  send_magic_packet(SOMEMAC, interface='192.168.2.2')

  send_magic_packet(SOMEMAC, interface='192.168.3.2')

Now I can wake up clients in both nets. That is great!

What I am asking: If I use your version WITHOUT the ‚interface=…‘-arg, then sometimes only clients in the first IP-range and sometimes only clients in the second IP-range wake up. I think the „default“-interfaces switches. So, is it possible to tell wakeonlan to send the magic packet to interface=all?

Thanks again for your work!

Markus

Von: VogelMoritz notifications@github.com Gesendet: Samstag, 29. Februar 2020 22:03 An: remcohaszing/pywakeonlan pywakeonlan@noreply.github.com Cc: erhardma markus@markus-erhard.de; Comment comment@noreply.github.com Betreff: Re: [remcohaszing/pywakeonlan] Update wakeonlan.py (#10)

Hi Markus,

if the target is connected with all interfaces, it's enough to send the package through one of the interfaces. If there a several targets on several interfaces, you can call the script several times with different IPs and interfaces. What is you exact use-case?

*Martin

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/remcohaszing/pywakeonlan/pull/10?email_source=notifications&email_token=AM6UZKS5JGVEXVGY6TAEPC3RFF3YPA5CNFSM4KXMN6H2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENMF72A#issuecomment-592994280 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AM6UZKRWBVL3N3R7OGZ64K3RFF3YPANCNFSM4KXMN6HQ . https://github.com/notifications/beacon/AM6UZKTQ7V4OLE3H3QMUWS3RFF3YPA5CNFSM4KXMN6H2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENMF72A.gif

mrtnRitter commented 4 years ago

Hi Markus,

thank you for the clearance.

My version of wakeonlan is for computers with several NICs installed. If you have only one NIC, a default interface is set and this default interface is read out from system and it is the IP of the NIC.

If you have several interfaces, it is MEANT to specified which NIC should be used.

If you do:

      send_magic_packet(SOMEMAC, interface='192.168.2.2')
      send_magic_packet(SOMEMAC, interface='192.168.3.2')

then this is exactly how the script should be used.

There are plenty of snippets about how to get all interfaces so you can wrap the script in something like:

get_all_interfaces_and_return_their_ips_in_a_list_called_interfaces()
for interface in interfaces:
      send_magic_packet(SOMEMAC, interface='interface')

*Martin

Trinity503 commented 4 years ago

Hello Martin,

yes, then I got it correctly. Thanks again. I hope, your commit will be merged with master!

Markus

Von: VogelMoritz notifications@github.com Gesendet: Dienstag, 3. März 2020 12:53 An: remcohaszing/pywakeonlan pywakeonlan@noreply.github.com Cc: erhardma markus@markus-erhard.de; Comment comment@noreply.github.com Betreff: Re: [remcohaszing/pywakeonlan] Update wakeonlan.py (#10)

Hi Markus,

thank you for the clearance.

My version of wakeonlan is for computers with several NICs installed. If you have only one NIC, a default interface is set and this default interface is read out from system and it is the IP of the NIC.

If you have several interfaces, it is MEANT to specified which NIC should be used.

If you do:

  send_magic_packet(SOMEMAC, interface='192.168.2.2')
  send_magic_packet(SOMEMAC, interface='192.168.3.2')

then this is exactly how the script should be used.

There are plenty of snippets about how to get all interfaces so you can wrap the script in something like:

get_all_interfaces_and_return_their_ips_in_a_list_called_interfaces() for interface in interfaces: send_magic_packet(SOMEMAC, interface='interface')

*Martin

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/remcohaszing/pywakeonlan/pull/10?email_source=notifications&email_token=AM6UZKWQFDAQ2VRPUK5MDKLRFTVQ7A5CNFSM4KXMN6H2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENTGIZQ#issuecomment-593912934 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AM6UZKTXFI6QYILBJW7DENLRFTVQ7ANCNFSM4KXMN6HQ . https://github.com/notifications/beacon/AM6UZKUQGW37KULZ3MFACEDRFTVQ7A5CNFSM4KXMN6H2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENTGIZQ.gif

remcohaszing commented 4 years ago

I am interested in looking a bit more into this change before just merging it. Currently I no longer have a setup to test WOL in an actual machine easily.

I’m planning on dropping support for Python 2 soon. That’ll include a code cleanup, but also requires me to test this on a real machine. I’ll take this PR into consideration then.

mrtnRitter commented 4 years ago

Hi Remco, that's nice. I just added a few lines and I'm pretty sure that I didn't used Python2 functions.