Skip to content

Wordpress check

#!/usr/bin/python3
import re

import requests
requests.packages.urllib3.disable_warnings()


def report(input_str):
    with open('output.txt', 'a') as f:
        print(input_str)
        f.write(input_str + '\n')


def get_version(text):
    versions = []
    prefix = "WordPress "
    for version in re.findall(prefix + "[0-9.]*", text, re.IGNORECASE):
        if len(str(version)) > len(prefix):
            versions.append(version)
    return versions

def get_metadata(target):
    try:
        page = requests.get(target, timeout=2, allow_redirects=True, verify=False)
        if page.status_code == 200:
            wordpress_detected = 'WordPress' in page.text
            wp_detected = 'wp-content' in page.text
            version = get_version(page.text)
            return "Url [{}] Wordpress [{}] WpContent [{}] Version {}".format(page.url, wordpress_detected, wp_detected, version)
        return "No page"
    except Exception as e:
        return "error"


with open("input.txt") as file:
    lines = file.readlines()
    for target_line in lines:
        target = target_line.strip()

        metadata_http = get_metadata("http://" + target)
        metadata_https = get_metadata("https://" + target)

        report("Target: {:15} Metadata: {}".format(
            target,
            metadata_http,
        ))

        report("Target: {:15} Metadata: {}".format(
            target,
            metadata_https
        ))

input.txt

127.0.0.1
127.0.0.2
127.0.0.3

output.txt

Target: 127.0.0.1 Metadata: Url [https://example.com] Wordpress [True] WpContent [True] Version ['WordPress 5.8.4']
Target: 127.0.0.2 Metadata: Url [https://example.com] Wordpress [True] WpContent [True] Version ['WordPress 5.8.4']
Target: 127.0.0.3 Metadata: Url [https://example.com] Wordpress [True] WpContent [True] Version ['WordPress 5.8.4']