Skip to content

Commit

Permalink
Finished routing table function operations on macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Loren Eteval <[email protected]>
  • Loading branch information
LorenEteval committed Sep 6, 2023
1 parent a688b0d commit a807d0d
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions Furious/Utility/RoutingTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class RoutingTable:
Relations = list()

DEFAULT_GATEWAY_WINDOWS = re.compile(
r'0\.0\.0\.0.*?0\.0\.0\.0.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
r'0\.0\.0\.0.*?0\.0\.0\.0.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})',
)
DEFAULT_GATEWAY_DARWIN = re.compile(
r'gateway:\s*(\S+)',
)

@staticmethod
Expand All @@ -35,8 +38,12 @@ def _add():

if PLATFORM == 'Darwin':
try:
# TODO: using networksetup
pass
runCommand(
['route', 'add', '-net', source, destination],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True,
)
except Exception:
# Any non-exit exceptions

Expand Down Expand Up @@ -79,8 +86,21 @@ def _get():
return []

if PLATFORM == 'Darwin':
# TODO
pass
try:
result = runCommand(
'route get default'.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
)

return RoutingTable.DEFAULT_GATEWAY_DARWIN.findall(
result.stdout.decode('utf-8', 'replace')
)
except Exception:
# Any non-exit exceptions

return []

defaultGateway = _get()

Expand Down Expand Up @@ -167,8 +187,12 @@ def _delete():

if PLATFORM == 'Darwin':
try:
# TODO: using networksetup
pass
runCommand(
['route', 'delete', '-net', source, destination],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True,
)
except Exception:
# Any non-exit exceptions

Expand All @@ -191,7 +215,7 @@ def deleteRelations(clear=True):
if len(RoutingTable.Relations):
RoutingTable.delete('0.0.0.0', APPLICATION_TUN_GATEWAY_ADDRESS)

for source, destination in RoutingTable.Relations:
for source, destination in RoutingTable.Relations[::-1]:
RoutingTable.delete(source, destination)

if clear:
Expand Down

0 comments on commit a807d0d

Please sign in to comment.