Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions aioarping/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

import subprocess, asyncio, aioarping, ipaddress
import asyncio, aioarping, ipaddress


from .utils import get_interface_and_network


def my_process(data):
Expand All @@ -33,15 +36,7 @@ def my_process(data):


event_loop = asyncio.get_event_loop()
mydomain = [
x
for x in subprocess.getoutput(
"ip route|sed '/via/d' |sed '/docker/d'|sed '/linkdown/d'|sed '/src /!d' | sed '/dev /!d' |sed '2,$d'"
).split(" ")
if x
]
myiface = mydomain[2]
mydomain = mydomain[0]
myiface, mydomain = get_interface_and_network()

# First create and configure a raw socket
mysocket = aioarping.create_raw_socket(myiface)
Expand Down
39 changes: 39 additions & 0 deletions aioarping/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def prefilter_route_lines(lines):
"""https://github.com/brandonmpace/routeparser/issues/2"""

for el in lines:
if "linkdown" in el:
continue
if "src" not in el:
continue
yield el


def post_filter_routes(routes):
for r in routes:
if "docker" in r.interface:
continue
if r.gateway is not None:
continue
yield r


def get_ip_route_lines():
import subprocess

return subprocess.getoutput("/usr/sbin/ip route").splitlines()


def get_needed_routes():
import routeparser

routeLines = list(prefilter_route_lines(get_ip_route_lines()))
t = routeparser.RoutingTable.from_ip_route_lines(routeLines)
return post_filter_routes(t.routes)


def get_interface_and_network():
r = next(iter(get_needed_routes()))
ifc = r.interface
domain = r.network
return ifc, domain
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[build-system]
requires = ["setuptools>=61.2.0", "wheel", "setuptools_scm[toml]>=3.4.3"]
build-backend = "setuptools.build_meta"

[project]
name = "aioarping"
authors = [{name = "François Wautier", email = "francois@wautier.eu"}]
license = {text = "MIT"}
description = "API for arping over a LAN with asyncio."
readme = "README.md"
keywords = ["arp", "mac address", "presence", "automation"]
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
]
urls = {Homepage = "http://github.com/frawau/aioarping"}
dependencies = ["ipaddress"]
dynamic = ["version"]

[project.optional-dependencies]
utils = ["routeparser"]
cli = ["aioarping[utils]"]

[tool.setuptools]
packages = ["aioarping"]

[tool.setuptools_scm]
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

25 changes: 0 additions & 25 deletions setup.py

This file was deleted.