I have some 40,000 lines of information in a file that I would like to extract the IP addresses of a certain system using Python 3.4. The file is broken into each block starting with "lease" and ends with "}". I would like to search for the "SYSTEM123456789" and extract the IP address "10.0.0.2". How do I go about doing that and what is the preferred approach?
1) Read in the file, break them up in the list, and then search?
2) Copy the file and then search within that file?
lease 10.0.0.1 {
starts 1 2015/06/29 07:22:01;
ends 2 2015/06/30 07:22:01;
tstp 2 2015/06/30 07:22:01;
cltt 1 2015/06/29 07:22:01;
binding state active;
next binding state free;
hardware ethernet 08:2e:5f:f0:8b:a1;
}
lease 10.0.0.2{
starts 1 2015/06/29 07:31:20;
ends 2 2015/06/30 07:31:20;
tstp 2 2015/06/30 07:31:20;
cltt 1 2015/06/29 07:31:20;
binding state active;
next binding state free;
hardware ethernet ec:b1:d7:87:6f:7a;
uid "\001\354\261\327\207oz";
client-hostname "SYSTEM123456789";
}
Aucun commentaire:
Enregistrer un commentaire