network.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:SamplerBox 作者: alexmacrae 项目源码 文件源码
def get_ip_address(self, interface):

        # Not a simple subprocess.call due to the need for a PIPE in the command
        # https://docs.python.org/2/library/subprocess.html#replacing-shell-pipeline
        command_line_1 = "ip addr show " + interface
        args1 = shlex.split(command_line_1)
        command_line_2 = "grep -Po 'inet \K[\d.]+'"
        args2 = shlex.split(command_line_2)

        command_line_1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
        command_line_2 = subprocess.Popen(args2, stdin=command_line_1.stdout, stdout=subprocess.PIPE)
        command_line_1.stdout.close()

        ip_address = command_line_2.communicate()[0]
        ip_address = ip_address.rstrip()

        if ip_address == '':
            ip_address = 'NOT CONNECTED'

        return str(ip_address)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号