#๐Ÿ”’ Wifi to ethernet bridging problemu

12 messages ยท Page 1 of 1 (latest)

gusty apex
#

I used this python script in order to bridge wifi to tehernet but it just crashes in 1 minute
from subprocess import check_call, check_output, Popen, PIPE, run
from sys import argv, exit
from threading import Thread
from time import sleep

def get_ip(interface_name):
return check_output(['ip', '-4', '-br', 'addr', 'show', interface_name]).decode('utf-8').strip().split()[-1]

def pre_start(ip, ethernet_interface, wireless_interface):
try:
check_call(['ip', 'addr', 'add', ip, 'dev', ethernet_interface])
check_call(['ip', 'link', 'set', 'dev', ethernet_interface, 'up'])
check_call(['ip', 'link', 'set', wireless_interface, 'promisc', 'on'])
except:
print('pre_start error')
# In case of error, try to clean up
pre_stop(ip, ethernet_interface, wireless_interface)
exit(1)

def pre_stop(ip, ethernet_interface, wireless_interface):
run(['ip', 'link', 'set', wireless_interface, 'promisc', 'off'], check=False)
run(['ip', 'link', 'set', 'dev', ethernet_interface, 'down'], check=False)
run(['ip', 'addr', 'del', ip, 'dev', ethernet_interface], check=False)

def start(ethernet_interface, wireless_interface):
with Popen(['parprouted', '-d', ethernet_interface, wireless_interface], stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True) as process:
for line in iter(process.stdout.readline, ''):
print(line, end='')
for line in iter(process.stderr.readline, ''):
print(line, end='')

if name == 'main':
is_up = False
ip = None
ethernet_interface = argv[1]
wireless_interface = argv[2]
task = None

try:
    while True:
        new_ip = get_ip(wireless_interface)

        if is_up:
            if task and not task.is_alive():
                pre_stop(ip, ethernet_interface, wireless_interface)
                print('process stopped unexpectedly', task)
                exit(1)
            if ip and not new_ip:
                pre_stop(ip, ethernet_interface, wireless_interface)
                print('ip disappeared')
                exit(1)

        ip = new_ip

        if ip and not is_up:
            print('starting...')
            pre_start(ip, ethernet_interface, wireless_interface)
            task = Thread(target=start, args=(ethernet_interface, wireless_interface,))
            task.start()
            is_up = True

        if not ip and is_up:
            print('stopping...')
            pre_stop(ip, ethernet_interface, wireless_interface)
            task.join()
            exit(0)

        sleep(1)

except KeyboardInterrupt:
    pre_stop(ip, ethernet_interface, wireless_interface)
    exit(0)

More information:https://www.willhaley.com/blog/raspberry-pi-wifi-ethernet-bridge/

limpid stormBOT
#

@gusty apex

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gusty apex
#

Wifi to ethernet bridging problem

main niche
#

!paste

limpid stormBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

main niche
#

Please paste your code in the pastebin above so it'll be easier to read.

gusty apex
#

Ok

main niche
#

Is there any error message when it crashes?

gusty apex
limpid stormBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.