import requests
import re

base_url = "http://192.168.1.48/.hidden/"

class Scrapper(object):

    number = 0

    def __init___(self):
        self.number = 0

    def get_links(self, url):
        ret = requests.get(url)
        rx = re.compile(r'.*href=\"(([a-z]|[A-Z]|[0-9])*).*')
        links = []
        for line in ret.text.split():
            match = rx.match(line)
            if match and match.group(1):
                links.append(match.group(1))
        return links

    def check_readme(self, url):
        r = requests.get(url)
        rx = re.compile(r'(([a-z]|[0-9])+)')
        match = rx.match(r.text)
        if match and match.group(1):
                print("Flag found!")
                print("Path: %s" % url)
                print("Try: %d" % self.number)
                return match.group(1)
        return None

    def process(self, url):
        for link in self.get_links(url):
            print("process: %s" % url + link + '/')
            if link == 'README':
                u = url + link
                ret = self.check_readme(u)
                if ret:
                    return ret
                self.number += 1
                continue
            ret = self.process(url + link + '/')
            if ret:
                return ret

s = Scrapper()     
flag = s.process(base_url)
print("The flag is:\n%s" % flag)
