Пример #1
0
    def receive(self, packetFilter):
        network_data = self.s.recv(2048)
        encoded = network_data.encode('hex')
        src_mac = encoded[12:24]
        # if src_mac == '080027c08ead':
        #     x = src_mac
        builder = PacketBuilder()
        if network_data and packetFilter.filter(builder, network_data):
            return builder.get_message(), builder.get_connection_info()

        return False
Пример #2
0
def handle_device_get_power(options):
    if "-help" in options:
        handle_help("device-get-power")
        return ""
    
    if "-a" in options:
        return PacketBuilder.build_device_get_power_packet(0)
    elif "-t" in options:
        target = int(options["-t"])
        return PacketBuilder.build_device_get_power_packet(target)
    else:
        print("invalid options. use -help to see usage")
        return ""
Пример #3
0
def handle_light_get_state(options):
    if "-help" in options:
        handle_help("light-get-state")
        return ""
    
    if "-a" in options:
        return PacketBuilder.build_light_get_state_packet(0)
    elif "-t" in options:
        target = int(options["-t"])
        return PacketBuilder.build_light_get_state_packet(target)
    else:
        print("invalid options. use -help to see usage")
        return ""
Пример #4
0
def handle_device_echo_request(options):
    if "-help" in options:
        handle_help("device-echo-request")
        return ""
    
    payload = "101010101010101"
    
    if "-a" in options:
        return PacketBuilder.build_device_echo_request_packet(0, payload)
    elif "-t" in options:
        target = int(options["-t"])
        return PacketBuilder.build_device_echo_request_packet(target, payload)
    else:
        print("invalid options. use -help to see usage")
        return ""
Пример #5
0
    def send(self, message, connection_info):
        data_pack = PacketBuilder()

        data_pack.buildEth(connection_info.src_mac, connection_info.dst_mac)

        data_pack.buildIp6(connection_info.src_ip, connection_info.dst_ip)

        data_pack.buildMsg(message)

        data_pack = data_pack.pack()

        self.s.sendto(data_pack, (INTERFACE_NAME, 0))
Пример #6
0
def handle_light_set_color(options):
    if "-help" in options:
        handle_help("light-set-color")
        return ""
    
    hue = -1
    saturation = -1
    brightness = -1
    kelvin = -1
    
    if "-h" in options:
        hue_value = int(options["-h"])
        hue = int(float(hue_value) / 360 * 65535)
    else:
        print("invalid options. -h is required. use -help to see usage")
        return ""
        
    if "-s" in options:
        saturation_value = int(options["-s"])
        saturation = int(float(saturation_value) / 100 * 65535)
    else:
        print("invalid options. -s is required. use -help to see usage")
        return ""
        
    if "-b" in options:
        brightness_value = int(options["-b"])
        brightness = int(float(brightness_value) / 100 * 65535)
    else:
        print("invalid options. -b is required. use -help to see usage")
        return ""
        
    if "-k" in options:
        kelvin = int(options["-k"])
    else:
        print("invalid options. -k is required. use -help to see usage")
        return ""
    
    if "-a" in options:
        return PacketBuilder.build_light_set_color_packet(0, hue, saturation, brightness, kelvin, 0)
    elif "-t" in options:
        target = int(options["-t"])
        return PacketBuilder.build_light_set_color_packet(target, hue, saturation, brightness, kelvin, 0)
    else:
        print("invalid options. use -help to see usage")
        return ""
Пример #7
0
def broadcast():

    #packet_bytes = PacketBuilder.build_light_get_state_packet()
    #packet_bytes = PacketBuilder.build_device_set_power_packet(1001, 127337741231970, 0)
    #packet_bytes = PacketBuilder.build_light_set_color_packet(127337741231970, 23040, 65535, 32766, 2999, 0)
    #packet_bytes = PacketBuilder.build_light_set_power_packet(1001, 127337741231970, 65535, 0)
    packet_bytes = PacketBuilder.build_device_get_host_info_packet()

    PacketBroadcaster.broadcast_packet("172.16.10.255", 56700, packet_bytes)
    return
Пример #8
0
def handle_device_set_power(options):
    if "-help" in options:
        handle_help("device-set-power")
        return ""
    
    level = -1
    if "-l" in options:
        level = int(options["-l"]) * 65535
    else:
        print("invalid options. -l is required. use -help to see usage")
        return ""
    
    if "-a" in options:
        return PacketBuilder.build_device_set_power_packet(0, level)
    elif "-t" in options:
        target = int(options["-t"])
        return PacketBuilder.build_device_set_power_packet(target, level)
    else:
        print("invalid options. use -help to see usage")
        return ""
Пример #9
0
def handle_device_set_label(options):#need to validate
    if "-help" in options:
        handle_help("device-set-label")
        return ""
    
    label = "N/A"
    if "-l" in options:
        label = options["-l"]
    else:
        print("invalid options. -l is required. use -help to see usage")
        return ""
    
    if "-t" in options:
        target = int(options["-t"])
        return PacketBuilder.build_device_set_label_packet(target, label)
    else:
        print("invalid options. use -help to see usage")
        return ""
Пример #10
0
import PacketBuilder

a = PacketBuilder.PacketBuilder()
a.A()
a.B()
Пример #11
0
#coding=utf-8
import PacketBuilder, time, socket, struct, dnet, dpkt
#a=PacketBuilder.PacketBuilder("\x5c\xf9\x38\xa6\x66\xfe","\x00\x00\x0c\x07\xac\x90")
a = PacketBuilder.PacketBuilder("\x5c\xf9\x38\xa6\x66\xfe",
                                "\x8c\xab\x8e\x6e\x56\xd8")

# a.A()
# t1=time.time()
# for i in range(1,10000000):
#     a.B()
# t2=time.time()
# print t2-t1
dip = struct.unpack(">I", socket.inet_aton("222.200.98.110"))[0]
dport = 80
sip = struct.unpack(">I", socket.inet_aton("192.168.1.110"))[0]
sport = 22222
seq = 1
ack = 0
flags = 0x02
payload = ''
payload_length = 0
packet = a.GetTcpPacket(dip, dport, sip, sport, seq, ack, flags, payload,
                        payload_length)
print len(packet)
print packet.encode('hex')

e = dnet.eth("en0")
e.send(packet)

t1 = time.time()
for i in range(1, 10000000):
Пример #12
0
def handle_device_get_service(options):
    if "-help" in options:
        handle_help("device-get-service")
        return ""
    else:
        return PacketBuilder.build_device_get_service_packet()