Web lists-archives.com

Re: get my ip address




On Fri 15 Feb 2019 at 12:02:20 (+0100), Markus Schönhaber wrote:
> Tony, 15.2.2019, 11:11:29 +0100:
> 
> > Debian 9. I need to read my IPv6 address into a python script.
> > 
> > I am aware that I can call ip a and parse the result. The parsing,
> > whilst quite achievable, is slightly tricky, but I can manage the RE, so
> >  that's not my question.
> > 
> > Is there any other way to obtain this data, maybe from /sys?
> 
> Take a look at this:
> https://pypi.org/project/netifaces/
> 
> This is packaged on stretch as python[3]-netifaces

That's probably best if your destination is a Python program.

Otherwise, for scripting, it's easy to overlook   ip -o a
which makes parsing much easier. But note that you may then
need to be more specific, eg compare

$ ip a

with

$ ip -o l
$ ip -o a

Cheers,
David.