[Tutor] printing all text that begins with "25"

John Doe dantheman5457 at gmail.com
Thu Oct 2 18:58:54 CEST 2014


Hello,

If you want to accomplish what you are looking for within linux
(perhaps a bash script, instead?):

$ hamachi list | grep -oP '25\.\d+\.\d+\.\d+'
25.0.0.0
25.255.255.255

For your python script, you want to group your regex:
reg = re.compile(r'(25\.\d+\.\d+\.\d+)', re.MULTILINE)

So when you call group(1) or group(0), it'll grab just the addresses.


On Thu, Oct 2, 2014 at 12:33 PM, David Rock <david at graniteweb.com> wrote:
> * Bo Morris <crushed26 at gmail.com> [2014-10-02 11:41]:
>> Hello all, hope everyone is doing well.
>>
>> When I run the linux command "hamachi list" i get something along the lines
>> of the following output
>>
>>        087-888-279   Pandora                    25.x.x.xxx       alias: not set
>>        096-779-867   AM1LaptopBD-PC    25.x.x.xxx       alias: not set
>>        097-552-220   OWS-Desktop 1        25.0.0.0          alias: not set
>>        099-213-641   DESKTOP                 25.0.0.0          alias: not set
>>
>> I am trying to write a python script that will run the above command and
>> only print out the IP's that begin with 25. How do I strip out all other
>> text except for the IP's that begin with "25?"
>
> There are a few assumptions that need to be made, for starters.
>
> Is the format always the same (ie, is the IP address always in column 3
> separated by whitespace)?  Looking at the line with "OWS-Desktop 1", the
> answer is no.  That complicates things a bit.  If it was true, you could
> use the string split method to get column 3.  Maybe the fields are
> separated by a tab?
>
> A regex may be possible, but you will have similar issues to using
> split.
>
> I'm also assuming it's possible for there to be IP addresses that do not
> start with 25. Are you looking to isolate those?
>
> It's not necessary to write out to a file first.  You can get the output
> from commands and work on it directly.
>
> Another approach would be to change the command you are running.  I've
> never heard of hamachi list before; does it have any commandline options
> to display only IP addresses?
>
> --
> David Rock
> david at graniteweb.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list