#!/usr/bin/python
#-- coding: utf-8 --
import os
import sys
def partition(str,sep):
return [str.split(sep)[0],sep,sep.join(str.split(sep)[1:])]
def rpartition(str,sep):
return [sep.join(str.split(sep)[:-1]),sep,str.split(sep)[-1]]
def getLocalips(system_type):
localips=set()
if system_type==‘Windows’:
cmd_getip=“ipconfig”
elif system_type==‘Linux’:
cmd_getip=“ip a”
localipline=os.popen(cmd_getip).readlines()
if system_type==‘Windows’:
localipline=[partition(partition(x,’:’)[2],’(’)[0].strip() for x in localipline if ‘IPv6’ in x or ‘IPv4’ in x]
elif system_type==‘Linux’:
localipline=[x.split()[1].split(’/’)[0] for x in localipline if ’ inet’ in x]
for ip in localipline:
localips.add(ip.rstrip(’\n’))
localips.add(‘0.0.0.0’)
localips.add(’::’)
temp=set()
for ip in locali