Merge pull request #2759 from gtortone/development

fw-server: add ip option
This commit is contained in:
Theo Arends 2018-05-17 18:07:49 +02:00 committed by GitHub
commit edf9a5cb76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

17
api/fw-server.py Normal file → Executable file
View File

@ -33,9 +33,13 @@ Instructions:
Usage:
./fw-server.py -d <net_iface> (default: eth0)
or
./fw-server.py -i <ip_address>
Example:
./fw-server.py -d wlan0
or
./fw-server.py -i 192.168.1.10
"""
import io
@ -45,16 +49,23 @@ from flask import Flask, send_file
from optparse import OptionParser
import netifaces as ni
parser = OptionParser()
usage = "usage: fw-server {-d | -i} arg"
parser = OptionParser(usage)
parser.add_option("-d", "--dev", action="store", type="string",
dest="netdev", default="eth0", help="network interface (default: eth0)")
parser.add_option("-i", "--ip", action="store", type="string",
dest="ip", help="IP address to bind")
(options, args) = parser.parse_args()
try:
if options.ip is None:
try:
netip = ni.ifaddresses(options.netdev)[ni.AF_INET][0]['addr']
except Exception as e:
except Exception as e:
print("E: network interface error - {}".format(e))
exit(1)
else:
netip = options.ip
app = Flask(__name__)