Skip to content

Commit

Permalink
Test interface is up before running
Browse files Browse the repository at this point in the history
  • Loading branch information
irl committed Oct 20, 2016
1 parent ea17f47 commit df6554a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
10 changes: 0 additions & 10 deletions pathspider/Network/test_interface.py

This file was deleted.

9 changes: 9 additions & 0 deletions pathspider/network/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

from pyroute2 import IPDB # pylint: disable=no-name-in-module

def interface_up(int):
with IPDB() as ipdb:
for interface in set(ipdb.interfaces.values()):
if interface.ifname == int and interface.operstate == 'UP':
return True
return False
7 changes: 6 additions & 1 deletion pathspider/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pathspider.base import SHUTDOWN_SENTINEL

from pathspider.network import interface_up

def job_feeder(inputfile, spider):
logger = logging.getLogger("feeder")
Expand All @@ -28,7 +29,11 @@ def run_standalone(args):

try:
if hasattr(args, "spider"):
spider = args.spider(args.workers, "int:" + args.interface, args)
if interface_up(args.interface):
spider = args.spider(args.workers, "int:" + args.interface, args)
else:
logger.error("The chosen interface is not up! Cannot continue.")
sys.exit(1)
else:
logger.error("Plugin not found! Cannot continue.")
logger.error("Use --help to list all plugins.")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
straight.plugin
dnspython
pyroute2

0 comments on commit df6554a

Please sign in to comment.