-
-
Save cxgreat2014/085e98ce38baf93fee8d7c2076a3faf7 to your computer and use it in GitHub Desktop.
Revisions
-
comzyh revised this gist
Nov 25, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,7 @@ def send_thread_func(s, nic=None): s.sendto(b'BREED:ABORT', ('255.255.255.255', 37541)) except Exception: print("Stop sending on {}".format(nic)) break -
comzyh revised this gist
Nov 25, 2019 . 2 changed files with 69 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ #!/usr/bin/env python3 import socket import time import threading import signal import sys import os sending = None def send_thread_func(s, nic=None): global sending while sending: time.sleep(0.1) try: s.sendto(b'BREED:ABORT', ('255.255.255.255', 37541)) except Exception: print("Stop sending on {}".format(nic)) def receive_thread_func(s, nic=None): global sending while sending: data, addr = s.recvfrom(2048) if data == b'BREED:ABORTED': print("BREED now running on {}\t{}".format(nic, addr[0])) print("http://{}".format(addr[0])) break sending = False def start_breed_enter(): global sending nics = os.listdir('/sys/class/net/') for nic in nics: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.setsockopt(socket.SOL_SOCKET, 25, nic.encode( 'utf-8')) # SO_BINDTODEVICE s.bind(('0.0.0.0', 37540)) sending = True receive_thread = threading.Thread(target=receive_thread_func, args=(s, nic)) send_thread = threading.Thread(target=send_thread_func, args=(s, nic)) receive_thread.daemon = True send_thread.daemon = True receive_thread.start() send_thread.start() print('start listening on {}'.format(nic)) print("Waiting breed to be discovered....") while sending: try: time.sleep(0.5) except KeyboardInterrupt: break print("QUIT") sys.exit(0) def main(): start_breed_enter() if __name__ == '__main__': main() File renamed without changes. -
comzyh revised this gist
Nov 25, 2019 . No changes.There are no files selected for viewing
-
comzyh created this gist
Nov 25, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ #!/usr/bin/env python3 import socket import time import threading import signal import sys sending = None def send_thread_func(s): global sending while sending: time.sleep(0.1) s.sendto(b'BREED:ABORT', ('255.255.255.255', 37541)) def receive_thread_func(s): global sending while sending: data, addr = s.recvfrom(2048) if data == b'BREED:ABORTED': print("BREED now running on {}".format(addr[0])) print("http://{}".format(addr[0])) break sending = False def start_breed_enter(): global sending s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.bind(('0.0.0.0', 37540)) sending = True receive_thread = threading.Thread(target=receive_thread_func, args=(s, )) send_thread = threading.Thread(target=send_thread_func, args=(s, )) receive_thread.daemon = True send_thread.daemon = True receive_thread.start() send_thread.start() print("Waiting breed to be discovered....") while sending: try: time.sleep(0.5) except KeyboardInterrupt: break print("QUIT") sys.exit(0) def main(): start_breed_enter() if __name__ == '__main__': main()