def receive(): thread.start_new_thread(alive, ()) MCAST_GRP = '224.1.1.1' MCAST_PORT = 5007 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) try: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) except AttributeError: pass sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1) sock.bind((MCAST_GRP, MCAST_PORT)) host = get_ip.get_lan_ip() sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(host)) sock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_GRP) + socket.inet_aton(host)) while 1: try: data, addr = sock.recvfrom(1024) if data != host: lock.acquire() ips[data] = time.time() lock.release() except socket.error, e: print 'Expection'
def main(options): G.GAME_MODE = options.game_mode G.SAVE_FILENAME = options.save G.DISABLE_SAVE = options.disable_save for name, val in options._get_kwargs(): setattr(G.LAUNCH_OPTIONS, name, val) G.TERRAIN_CHOICE = options.terrain G.TERRAIN = G.TERRAIN_CHOICES[options.terrain] G.FLAT_MODE = options.flat if options.fast: G.TIME_RATE /= 20 # try: # window_config = Config(sample_buffers=1, samples=4) #, depth_size=8) #, double_buffer=True) #TODO Break anti-aliasing/multisampling into an explicit menu option # window = Window(resizable=True, config=window_config) # except pyglet.window.NoSuchConfigException: window = Window(resizable=True, vsync=False) local_ip = get_lan_ip() local_ip = (local_ip) print("local ip: " + local_ip) G.main_timer = Timer() pyglet.clock.schedule_interval(G.main_timer.schedule, G.TIMER_INTERVAL) pyglet.app.run()
def send(): host = get_ip.get_lan_ip() MCAST_GRP = '224.1.1.1' MCAST_PORT = 5007 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32) while True: sock.sendto(host, (MCAST_GRP, MCAST_PORT)) time.sleep(3)
def get(self): try: host = os.environ['OPENSHIFT_APP_DNS'] port = options.port uri = '/ws' self.render("client.html", **{'host': host, 'port': port, 'uri': uri}) except: host = get_lan_ip() port = options.port uri = '/ws' self.render("templates/client.html", **{'host': host, 'port': port, 'uri': uri})
# -*- coding:utf-8 -*- import socket import os import struct from ctypes import * import threading import time from netaddr import IPNetwork, IPAddress from get_ip import get_lan_ip # host = socket.gethostbyname(socket.gethostname()) host = get_lan_ip() print "local ip is %s" % host subnet = "192.168.1.0/24" # 校验字符串 magic_message = "PYTHONRULES" # 批量发送UDP数据包 def udp_sender(sub_net, message): time.sleep(5) sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for ip in IPNetwork(sub_net): try: sender.sendto(message, ("%s" % ip, 65212)) except: pass
#!/usr/bin/env python """ @author : 'Muhammad Arslan <*****@*****.**>' """ import socket import os import get_ip #host to listen on host = get_ip.get_lan_ip() if os.name == "nt": socket_protocol = socket.IPPROTO_IP else: socket_protocol = socket.IPPROTO_ICMP sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket_protocol) sniffer.bind((host, 0)) #allow ip headers in captured packets sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # in windows, need o set IOCTL to set up promiscous mode if os.name == "nt": sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
import thread import get_ip from random import randint import logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) app = Flask(__name__) participant = False leader_UID = 0 my_UID = randint(1, 1000000) ip = get_ip.get_lan_ip() print(ip) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} pi = raw_input("What is my port?: ") next_pi = raw_input("What is the port of the node is next to me?: ") def send_UID(UID, path): participant = True connection = HTTPConnection(ip, next_pi, timeout=10) connection.request("POST", ("/" + path), urllib.urlencode({'UID' : UID}), headers) response = connection.getresponse()
""" @author : 'Muhammad Arslan <*****@*****.**>' """ import os import threading import time from netaddr import IPNetwork, IPAddress import socket import struct from ctypes import * from get_ip import get_lan_ip host = get_lan_ip() subnet = '.'.join(host.split('.')[:3]) + '.0/24' magic_message = "VOLF" def udp_sender(host, subnet, magic_message): time.sleep(5) sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) addr = filter(lambda x: x != host, IPNetwork(subnet)) for ip in addr: try: sender.sendto(magic_message, ("%s" % ip, 65212)) except: pass
import thread import get_ip from random import randint import logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) app = Flask(__name__) participant = False leader_UID = 0 my_UID = randint(1, 1000000) ip = get_ip.get_lan_ip() print(ip) headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } pi = raw_input("What is my port?: ") next_pi = raw_input("What is the port of the node is next to me?: ") def send_UID(UID, path): participant = True connection = HTTPConnection(ip, next_pi, timeout=10) connection.request("POST", ("/" + path), urllib.urlencode({'UID': UID}),