Not sure this question has it's place, but i'll give it a shot anyway. Basically what I need is to parse a conf file.
It would look like this :
1. #local-data: "some.dns.url IN MX 192.168.80.45"
2. local-data: "some.other.dns.url IN A 192.168.60.1"
3. local-data: "router.home.somewhere IN A 192.168.20.1"
4. *a linebreak*
5. local-data-ptr: "192.168.80.45 some.dns.url"
6. local-data-ptr: "192.168.60.1 some.other.dns.url"
7. # some other random comment
8. local-data-ptr: "192.168.20.1 router.home.somewhere"
What i'd need to get off of it is : The address : "some.other.dns.url" on the 2nd line what is after the "IN" : that can be MX, A, some others. The IP : in that case 192.168.60.1, but that could be anything else.
I don't necessarily need the complete script. Hell I don't even really need one, that's not my goal posting here. I would like to know the best approach for such a case. Most of the time I tend to get out of situations like that, but this time this seems a bit tricky as :
I can't base myself on the size of the line.
I can't base myself on "dots"
(.)for the address, as one could have 2 dots, and another one have 3.I have part of the line (
"IN") that is just disturbing and not of some use.
What i've done so far :
dnsconf = open('theconffile.conf', 'r')
dnsconf = dnsconf.readlines()
x = []
for line in dnsconf:
cont = re.findall('\"(.+?)\"', line)
if len(line) > 1 and line[:1] is not '#':
x.append(cont)
print cont
cont basically contains what is inside the double quotes. "some.dns.url IN MX 192.168.80.45" for exemple.
I feel like this is a good start but I fail to see how to continue from there. I am not good with regexes and I feel like what I need are actually regexes...so i'm a little bit stuck here.
Can anyone put me on the right track for this problem?
.*\s+IN\s+(?:A|MX|...)\s+(.*?)"\s*$?