0
함수에서 반환 값을 시도하는 중 오류가 발생합니다. dg가 정의되지 않았다고 잘못 설명 할 수 있습니까?Python 3 - 함수에서 값을 반환합니다.
ipl = socket.gethostbyname(socket.gethostname())
seg1,seg2,seg3,seg4=ipl.split(".")
ip2 = seg1+"."+seg2+"."+seg3+"."
ip3 = seg1+"."+seg2+"."+seg3+"."
def getDGW(ip3):
cmd = 'ipconfig'
p = subprocess.Popen(cmd , stdout=subprocess.PIPE,stderr=subprocess.PIPE)
for line in p.stdout:
x = re.findall('Default Gateway',str(line))
if x:
regex = ip3 + r'[0-9]+'
line = re.search(regex, str(line))
if line:
print(line.group(0))
dg = line.group(0)
return (dg)
getDGW(ip3)
print(dg)