簡體   English   中英

將 Internet 訪問腳本列入白名單

[英]Whitelist a script for Internet Access

我們有一個 Windows 服務器和一個 linux 服務器。 兩台服務器上都沒有互聯網。 現在,我們需要在這些服務器上部署一個 python 腳本,它將向外部網絡 url 發出 http get 請求。 所以,我需要互聯網。 但是我們無法為所有應用程序啟用互聯網。 有沒有辦法只為這個特定的腳本啟用互聯網?

我不太了解 Linux 平台,但您可以允許程序使用命令行從 python 發出傳出請求,如下所示:

import sys
import os

def allow_outbound_connections(program_path):
    """
    Allow program outbound connections.
    """
    if "win" in sys.platform:
        command = f'netsh advfirewall firewall add rule name="{program_path}" '\
              'dir=out action=block program= "{os.path.basename(program_path}"'\
              ' enable=yes profile=any'
    if "linux" in sys.platform:
        # *Add a similar command in Linux*

    with os.popen(command) as stream:
        return stream.read()


def main():
    # First allow this program to make outbound connections.
    output = allow_outbound_connections(__file__)
    # (Eventually you could handle the output)

    # Now make request to an outside network url.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM