41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
""" Small module that import browser fingerprints into the databose,
|
|
based on the data listed in https://huit.re/user-agent-json.
|
|
"""
|
|
|
|
import json
|
|
from django.core.management.base import BaseCommand
|
|
from django.db import models
|
|
from profiles.models import BrowserFingerprint
|
|
|
|
def import_file(filename):
|
|
with open(filename, mode='r') as file:
|
|
data = json.load(file)
|
|
data = data[0]["list"]
|
|
for os_agent in data:
|
|
for useragent in os_agent["useragents"]:
|
|
import_useragent(useragent)
|
|
|
|
def import_useragent(useragent):
|
|
fingerprint = BrowserFingerprint(
|
|
description=useragent.get("description", ""),
|
|
useragent=useragent.get("useragent", ""),
|
|
appname=useragent.get("appname", ""),
|
|
appversion=useragent.get("appversion", ""),
|
|
platform=useragent.get("appversion", ""),
|
|
vendor=useragent.get("vendor", ""),
|
|
vendorsub=useragent.get("vendorsub", ""),
|
|
buildID=useragent.get("buildID", ""),
|
|
oscpu=useragent.get("oscpu", ""),
|
|
accept_encoding=useragent.get("accept_encoding", ""),
|
|
accept_default=useragent.get("accept_default", ""),
|
|
accept_lang=useragent.get("accept_lang", ""),
|
|
pixeldepth=int(useragent.get("pixeldepth", 0)),
|
|
colordepth=int(useragent.get("colordepth", 0)),
|
|
screens=useragent.get("screen", ""),
|
|
)
|
|
print(fingerprint)
|
|
fingerprint.save()
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **kwargs):
|
|
import_file("data/user-agent.json")
|