I need to write a simple python (python3) script to store my local Ip address in a variable in order to manipulate it later, I read a lot around but I don't understand where I'm doing wrong here a chunk of code for a better understanding..
#!/usr/bin/env pyhton3
import os
import subprocess
import sys
import fileinput
localip = subprocess.call(["ifconfig | grep 'inet addr' | cut -d ':' -f2 | grep 'Bcast' | cut -d ' ' -f1"], shell=True)
print localip
...
...
...
now when I excecute it it prints me this:
pi@raspberrypi:~/Documents $ python change.py
192.168.1.6
0
It seems I can't find a solution to this on my own, can anyone tell me where I'm doing wrong and help me out? thanks.
subprocess.callis the command's return code, which is used to indicate whether the command succeeded. In this case it is zero, because there was no error.