Skip to content
This repository was archived by the owner on Sep 4, 2022. It is now read-only.

Commit bdb61a9

Browse files
Allow interface selection
1 parent 0ec14da commit bdb61a9

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

ubnt_discovery.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import argparse
1010
import json
1111
from random import randint
12-
from scapy.all import *
12+
13+
from scapy.all import (
14+
Ether, IP, UDP, Raw,
15+
get_if_hwaddr, get_if_list, conf, srp)
16+
1317

1418
# UBNT field types
1519
UBNT_MAC = '01'
@@ -40,6 +44,8 @@
4044
def parse_args():
4145
parser = argparse.ArgumentParser(
4246
description="Discovers ubiquiti devices on network using ubnt device discovery protocol")
47+
parser.add_argument(
48+
'interface', help="the interface you want to use for discovery")
4349
parser.add_argument(
4450
'--output-format', type=str, default='text', choices=('text', 'json'),
4551
help="output format")
@@ -49,12 +55,18 @@ def parse_args():
4955

5056
def ubntDiscovery():
5157

58+
if not iface in get_if_list():
59+
raise ValueError('{} is not a valid network interface'.format(iface))
60+
61+
src_mac = get_if_hwaddr(iface)
62+
5263
# Prepare and send our discovery packet
5364
conf.checkIPaddr = False # we're broadcasting our discovery packet from a local IP (local->255.255.255.255)
5465
# but we'll expect a reply on the broadcast IP as well (radioIP->255.255.255.255),
5566
# not on our local IP.
5667
# Therefore we must disable destination IP checking in scapy
57-
ubnt_discovery_packet = Ether(dst="ff:ff:ff:ff:ff:ff")/\
68+
conf.iface = iface
69+
ubnt_discovery_packet = Ether(dst="ff:ff:ff:ff:ff:ff", src=src_mac)/\
5870
IP(dst="255.255.255.255")/\
5971
UDP(sport=randint(1024,65535),dport=10001)/\
6072
Raw(UBNT_REQUEST_PAYLOAD.decode('hex'))

0 commit comments

Comments
 (0)