Friday, October 30, 2026

holy fuck

#!/usr/bin/env python3
"""Log in from the shell.

Usage:
    ./_login.py -u YOUR_USERNAME_OR_EMAIL
    PO_PASSWORD='secret' ./_login.py -u you@example.com --cookies po.txt

The password is read from the PO_PASSWORD environment variable or, if that is
unset, prompted for without echo. On success the session cookies are saved in
Netscape format (default: ~/._cookies.txt, mode 600), so you can
reuse them with curl:
    curl -b ~/._cookies.txt https://.org/account

Only the Python standard library is needed.
"""
import argparse
import getpass
import http.cookiejar
import os
import re
import sys
import urllib.error
import urllib.parse
import urllib.request
from html.parser import HTMLParser

UA = "Mozilla/5.0 (X11; Linux x86_64) -login-script/1.0"


class FormParser(HTMLParser):
    """Collects every <form> with its action, method and <input> fields."""

    def __init__(self):
        super().__init__()
        self.forms = []
        self._cur = None

    def handle_starttag(self, tag, attrs):
        a = dict(attrs)
        if tag == "form":
            self._cur = {"action": a.get("action", ""),
                         "method": a.get("method", "get").lower(),
                         "inputs": []}
            self.forms.append(self._cur)
        elif tag == "input" and self._cur is not None:
            self._cur["inputs"].append(a)

    def handle_endtag(self, tag):
        if tag == "form":
            self._cur = None


class ErrorParser(HTMLParser):
    """Pulls out error messages (class contains 'error')."""

    def __init__(self):
        super().__init__()
        self.messages = []
        self._depth = 0
        self._buf = []

    def handle_starttag(self, tag, attrs):
        cls = dict(attrs).get("class") or ""
        if self._depth:
            self._depth += 1
        elif "error" in cls:
            self._depth = 1
            self._buf = []

    def handle_endtag(self, tag):
        if self._depth:
            self._depth -= 1
            if self._depth == 0:
                text = " ".join("".join(self._buf).split())
                if text:
                    self.messages.append(text)

    def handle_data(self, data):
        if self._depth:
            self._buf.append(data)


def find_login_form(html):
    parser = FormParser()
    parser.feed(html)
    for form in parser.forms:
        names = {i.get("name") for i in form["inputs"]}
        if "emailhandle" in names and "password" in names:
            return form
    return None


def main():
    ap = argparse.ArgumentParser(description="Log in ")
    ap.add_argument("-u", "--user", required=True, help="username or email")
    ap.add_argument("--base", default="https://.org",
                    help="site root (default: %(default)s; cookies differ "
                         "between the www and non-www hosts)")
    ap.add_argument("--cookies",
                    default=os.path.expanduser("~/._cookies.txt"),
                    help="where to save session cookies (default: %(default)s)")
    ap.add_argument("--no-remember", action="store_true",
                    help="don't tick 'remember me'")
    args = ap.parse_args()

    password = os.environ.get("PO_PASSWORD") or getpass.getpass("Password: ")

    jar = http.cookiejar.MozillaCookieJar(args.cookies)
    opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))
    opener.addheaders = [("User-Agent", UA)]

    login_url = args.base.rstrip("/") + "/login"

    # 1. Fetch the login page: gets the session cookie and the hidden CSRF "code".
    try:
        with opener.open(login_url, timeout=30) as r:
            page_url = r.geturl()
            html = r.read().decode("utf-8", "replace")
    except (urllib.error.URLError, OSError) as e:
        sys.exit(f"Could not reach {login_url}: {e}")

    form = find_login_form(html)
    if form is None:
        sys.exit("Could not find the login form (already logged in, or the "
                 "site layout changed).")

    # 2. Build the POST body from the form's own fields, then fill in ours.
    data = {}
    for inp in form["inputs"]:
        name = inp.get("name")
        if not name or inp.get("type") in ("submit", "button", "image"):
            continue
        if inp.get("type") == "checkbox" and "checked" not in inp:
            continue
        data[name] = inp.get("value", "")
    data["emailhandle"] = args.user
    data["password"] = password
    data["dologin"] = "1"
    if not args.no_remember:
        data["remember"] = "1"

    action = urllib.parse.urljoin(page_url, form["action"] or login_url)

    # 3. Submit.
    body = urllib.parse.urlencode(data).encode()
    req = urllib.request.Request(action, data=body,
                                 headers={"Referer": page_url})
    try:
        with opener.open(req, timeout=30) as r:
            result = r.read().decode("utf-8", "replace")
            final_url = r.geturl()
    except (urllib.error.URLError, OSError) as e:
        sys.exit(f"Login request failed: {e}")

    # 4. Success = the page no longer shows a login form and offers a logout link.
    still_login = find_login_form(result) is not None
    has_logout = bool(re.search(r'href="[^"]*(?:qa=logout|/logout)', result))

    if has_logout and not still_login:
        jar.save(ignore_discard=True, ignore_expires=True)
        os.chmod(args.cookies, 0o600)
        print(f"Logged in as {args.user} ({final_url})")
        print(f"Cookies saved to {args.cookies}")
        return 0

    errors = ErrorParser()
    errors.feed(result)
    print("Login failed.", file=sys.stderr)
    for m in dict.fromkeys(errors.messages):
        print(f"  site says: {m}", file=sys.stderr)
    if re.search(r"anti-spam|captcha", result, re.I):
        print("  The site is asking for an anti-spam check, which this "
              "script cannot solve; log in once in a browser.", file=sys.stderr)
    return 1


if __name__ == "__main__":
    sys.exit(main())

this is the most complicated thing imaginable. im so proud

perl
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(uname getpid);

# High-level POSIX wrappers (preferred over raw syscall when available)
print "PID: ", getpid(), "\n";
print "System: ", join(" ", uname()), "\n";

# Raw syscall() example — call getpid(2) directly by number
# Syscall numbers are architecture-specific; check /usr/include/asm/unistd_64.h on Linux x86_64
my $SYS_getpid = 39; # x86_64 Linux
my $pid = syscall($SYS_getpid);
print "Raw syscall PID: $pid\n";

h2xs -A -n Sys::MyCalls cd Sys-MyCalls

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <unistd.h>
#include <sys/types.h>

MODULE = Sys::MyCalls PACKAGE = Sys::MyCalls

int
my_getpid()
CODE:
RETVAL = getpid();
OUTPUT:
RETVAL

int
my_fork()
CODE:
RETVAL = fork();
OUTPUT:
RETVAL


perl Makefile.PL make make test

use Sys::MyCalls;
print Sys::MyCalls::my_getpid(), "\n";


this is what im most most proud of

import urllib.request

URL = "prg"

# Some sites reject the default Python user agent, so send a browser-like one.
req = urllib.request.Request(
    URL,
    headers={"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
                           "(KHTML, like Gecko) Chrome/124.0 Safari/537.36"},
)

with urllib.request.urlopen(req, timeout=15) as resp:
    html = resp.read().decode(resp.headers.get_content_charset() or "utf-8", errors="replace")

print(f"Status: {resp.status}, length: {len(html)} characters\n")
print(html)

# Optionally save it to a file:
with open("user", "w", encoding="utf-8") as f:
    f.write(html)


#!/usr/bin/env perl
#
# pagesource.pl - fetch a web page (or read a local HTML file), save its
# source, and print an analysis report.
#
# Core modules only: HTTP::Tiny, Getopt::Long, Digest::MD5, JSON::PP,
# Encode, Time::HiRes.
#
# Examples:
# perl pagesource.pl user
# perl pagesource.pl --url dx --out page.html --links --top 15
# perl pagesource.pl --file page.html --base https://example.com/docs/ --json
#
use strict;
use warnings;
use feature 'say';
use Getopt::Long qw(GetOptions);
use HTTP::Tiny;
use Digest::MD5 qw(md5_hex);
use JSON::PP;
use Encode qw(decode);
use Time::HiRes qw(time sleep);

binmode STDOUT, ':encoding(UTF-8)';
binmode STDERR, ':encoding(UTF-8)';

my $ATTR = qr/(?:"[^"]*"|'[^']*'|[^>"'])/;

# --------------------------------------------------------------------------
# Command line
# --------------------------------------------------------------------------
my %opt = (
agent => 'Mozilla/5.0 (X11; Linux x86_64) pagesource.pl/1.0',
timeout => 15,
retries => 3,
top => 10,
links => 0,
);

GetOptions(
\%opt, 'url=s', 'file=s', 'out=s', 'agent=s', 'timeout=i', 'retries=i',
'top=i', 'links!', 'json', 'print-source|print', 'base=s', 'help|h',
) or usage(2);
usage(0) if $opt{help};

$opt{url} //= shift @ARGV;
usage(2, 'Give a URL or --file.') unless $opt{url} || $opt{file};
usage(2, 'Use either a URL or --file, not both.') if $opt{url} && $opt{file};

if ($opt{url} && $opt{url} !~ m{^[a-z][a-z0-9+.-]*://}i) {
$opt{url} = "https://$opt{url}";
}

# --------------------------------------------------------------------------
# Get the HTML
# --------------------------------------------------------------------------
my ($html, $meta);
if ($opt{file}) {
($html, $meta) = read_local($opt{file});
} else {
($html, $meta) = fetch_url($opt{url}, \%opt);
}

if ($opt{out}) {
open my $fh, '>:encoding(UTF-8)', $opt{out}
or die "Cannot write $opt{out}: $!\n";
print {$fh} $html;
close $fh;
warn "Saved source to $opt{out}\n";
}

print $html, "\n" if $opt{'print-source'};

# --------------------------------------------------------------------------
# Analyze and report
# --------------------------------------------------------------------------
my $base = $opt{base} // ($opt{url} ? $meta->{final_url} // $opt{url} : undef);
my $info = analyze($html, $base);
$info->{fetch} = $meta;

if ($opt{json}) {
say JSON::PP->new->utf8(0)->pretty->canonical->encode($info);
} else {
print_report($info, \%opt);
}
exit 0;

# ==========================================================================
# Fetching
# ==========================================================================
sub read_local {
my ($path) = @_;
open my $fh, '<:raw', $path or die "Cannot read $path: $!\n";
local $/;
my $raw = <$fh>;
close $fh;
return (decode('UTF-8', $raw, Encode::FB_DEFAULT),
{ source => "file:$path", bytes => length $raw });
}

sub fetch_url {
my ($url, $o) = @_;
my $http = HTTP::Tiny->new(
agent => $o->{agent},
timeout => $o->{timeout},
max_redirect => 5,
verify_SSL => 1,
);

my ($res, $t0);
for my $attempt (1 .. $o->{retries}) {
$t0 = time;
$res = $http->get($url, { headers => { 'Accept-Encoding' => 'identity' } });
last if $res->{success};

my $status = $res->{status};
my $retryable = $status >= 500; # 599 = connection-level failure
my $why = $status == 599 ? ($res->{content} // 'connection error')
: "HTTP $status $res->{reason}";
chomp $why;
if (!$retryable || $attempt == $o->{retries}) {
die "Failed to fetch $url: $why\n";
}
my $wait = 2**($attempt - 1);
warn "Attempt $attempt failed ($why); retrying in ${wait}s...\n";
sleep $wait;
}

my $elapsed = time - $t0;
my $ctype = $res->{headers}{'content-type'} // '';
my $charset = $ctype =~ /charset=["']?([\w-]+)/i ? $1 : 'UTF-8';
my $text = eval { decode($charset, $res->{content}, Encode::FB_DEFAULT) }
// decode('UTF-8', $res->{content}, Encode::FB_DEFAULT);

return ($text, {
source => $url,
final_url => $res->{url},
status => $res->{status},
content_type => $ctype,
server => $res->{headers}{server} // '',
bytes => length $res->{content},
seconds => sprintf('%.2f', $elapsed),
});
}

# ==========================================================================
# Analysis
# ==========================================================================
sub analyze {
my ($html, $base) = @_;
my %r = (
bytes_decoded => length $html,
md5 => md5_hex(do { my $c = $html; utf8::encode($c); $c }),
lines => scalar(() = $html =~ /\n/g) + 1,
);

# Strip comments, and the bodies of <script>/<style>, before analysis.
my $clean = $html;
$r{comments} = () = $clean =~ /<!--.*?-->/gs;
$clean =~ s/<!--.*?-->//gs;

$r{inline_scripts} = $r{inline_script_bytes} = 0;
$clean =~ s{(<script\b$ATTR*>)(.*?)</script\s*>}{
my ($open, $body) = ($1, $2);
if ($body =~ /\S/) {
$r{inline_scripts}++;
$r{inline_script_bytes} += length $body;
}
"$open</script>"
}gise;

$r{inline_styles} = 0;
$clean =~ s{(<style\b$ATTR*>)(.*?)</style\s*>}{
my ($open, $body) = ($1, $2);
$r{inline_styles}++ if $body =~ /\S/;
"$open</style>"
}gise;

# Walk every tag once.
my (%tags, %meta, @hrefs, @imgs, @scripts, @styles);
while ($clean =~ /<([a-zA-Z][a-zA-Z0-9-]*)\b($ATTR*)>/g) {
my ($tag, $attrs) = (lc $1, $2);
$tags{$tag}++;
my %a = parse_attrs($attrs);

if ($tag eq 'a' && defined $a{href}) { push @hrefs, $a{href} }
elsif ($tag eq 'img' && defined $a{src}) { push @imgs, $a{src} }
elsif ($tag eq 'script' && defined $a{src}) { push @scripts, $a{src} }
elsif ($tag eq 'link' && defined $a{href}
&& ($a{rel} // '') =~ /stylesheet/i) { push @styles, $a{href} }
elsif ($tag eq 'html' && defined $a{lang}) { $r{lang} = $a{lang} }
elsif ($tag eq 'meta') {
$meta{charset} = $a{charset} if defined $a{charset};
my $key = $a{name} // $a{property} // $a{'http-equiv'};
$meta{lc $key} = $a{content} if defined $key && defined $a{content};
}
}
$r{tags} = \%tags;
$r{tag_total} = 0;
$r{tag_total} += $_ for values %tags;
$r{meta} = \%meta;

# Title
if ($clean =~ m{<title\b[^>]*>(.*?)</title>}is) {
$r{title} = squash(strip_tags($1));
}

# Heading outline
my @outline;
while ($clean =~ m{<(h[1-6])\b$ATTR*>(.*?)</\1\s*>}gis) {
my $text = squash(strip_tags($2));
push @outline, { level => substr(lc $1, 1), text => $text } if length $text;
}
$r{outline} = \@outline;

# Visible text
my $text = squash(strip_tags($clean));
$r{text_chars} = length $text;
$r{words} = () = $text =~ /\w+/g;

# Links
my $host = host_of($base);
my (%seen, @internal, @external, @other);
for my $href (@hrefs) {
$href =~ s/^\s+|\s+$//g;
next if $href eq '' || $href =~ /^#/;
if ($href =~ /^(?:mailto|tel|javascript|data):/i) {
push @other, $href;
next;
}
my $abs = resolve_url($base, $href) // $href;
$abs =~ s/#.*//;
next if $seen{$abs}++;
my $h = host_of($abs);
if ($h ne '' && $host ne '' && $h ne $host) { push @external, $abs }
elsif ($h ne '') { push @internal, $abs }
else { push @other, $abs }
}
$r{links} = {
internal => \@internal,
external => \@external,
other => \@other,
};
$r{resources} = {
images => [ map { resolve_url($base, $_) // $_ } @imgs ],
scripts => [ map { resolve_url($base, $_) // $_ } @scripts ],
stylesheets => [ map { resolve_url($base, $_) // $_ } @styles ],
};

# External domains ranked by link count.
my %domains;
$domains{ host_of($_) }++ for @external;
$r{top_external_domains} = [
map { { domain => $_, links => $domains{$_} } }
sort { $domains{$b} <=> $domains{$a} || $a cmp $b } keys %domains
];

return \%r;
}

sub parse_attrs {
my ($s) = @_;
my %a;
while ($s =~ /([a-zA-Z_:][-\w:.]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g) {
my $name = lc $1;
my $val = $2 // $3 // $4 // '';
$a{$name} //= decode_entities($val);
}
return %a;
}

sub strip_tags { my ($s) = @_; $s =~ s/<[^>]*>/ /g; return decode_entities($s) }
sub squash { my ($s) = @_; $s =~ s/\s+/ /g; $s =~ s/^ | $//g; return $s }

sub decode_entities {
my ($s) = @_;
my %named = (amp => '&', lt => '<', gt => '>', quot => '"',
apos => "'", nbsp => ' ', copy => "\x{A9}", mdash => "\x{2014}");
$s =~ s{&(?:#(\d+)|#x([0-9a-fA-F]+)|(\w+));}{
defined $1 ? chr($1)
: defined $2 ? chr(hex $2)
: exists $named{lc $3} ? $named{lc $3}
: "&$3;"
}ge;
return $s;
}

sub host_of {
my ($url) = @_;
return '' unless defined $url && $url =~ m{^https?://([^/:?#]+)}i;
(my $h = lc $1) =~ s/^www\.//;
return $h;
}

sub resolve_url {
my ($base, $href) = @_;
return $href if $href =~ m{^[a-z][a-z0-9+.-]*:}i;
return undef unless defined $base
&& $base =~ m{^(https?:)//([^/?#]+)([^?#]*)}i;
my ($scheme, $auth, $path) = ($1, $2, $3);

return "$scheme$href" if $href =~ m{^//};
return "$scheme//$auth$href" if $href =~ m{^/};

$path =~ s{[^/]*$}{};
$path = '/' if $path eq '';
my @out;
for my $seg (split m{/}, $path . $href, -1) {
if ($seg eq '..') { pop @out if @out > 1 }
elsif ($seg eq '.') { next }
else { push @out, $seg }
}
return "$scheme//$auth" . join('/', @out);
}

# ==========================================================================
# Reporting
# ==========================================================================
sub print_report {
my ($i, $o) = @_;
my $f = $i->{fetch};

say '=' x 64;
say 'PAGE SOURCE REPORT';
say '=' x 64;
printf "%-16s %s\n", 'Source:', $f->{source};
printf "%-16s %s\n", 'Final URL:', $f->{final_url} if $f->{final_url};
printf "%-16s %s\n", 'HTTP status:', $f->{status} if $f->{status};
printf "%-16s %s\n", 'Content-Type:', $f->{content_type} if $f->{content_type};
printf "%-16s %s\n", 'Server:', $f->{server} if $f->{server};
printf "%-16s %s bytes%s\n", 'Size:', commify($f->{bytes}),
$f->{seconds} ? " in $f->{seconds}s" : '';
printf "%-16s %s\n", 'Lines:', commify($i->{lines});
printf "%-16s %s\n", 'MD5:', $i->{md5};
printf "%-16s %s\n", 'Language:', $i->{lang} if $i->{lang};
printf "%-16s %s\n", 'Title:', $i->{title} // '(none)';
say '';

my $desc = $i->{meta}{description} // $i->{meta}{'og:description'};
if (defined $desc) {
$desc = substr($desc, 0, 197) . '...' if length $desc > 200;
say "Description: $desc";
say '';
}

say '-- Content ' . '-' x 52;
printf "Words: %s Characters of text: %s Comments: %d\n",
commify($i->{words}), commify($i->{text_chars}), $i->{comments};
printf "Inline scripts: %d (%s bytes) Inline styles: %d\n",
$i->{inline_scripts}, commify($i->{inline_script_bytes}), $i->{inline_styles};
say '';

say "-- Top $o->{top} tags (of " . commify($i->{tag_total}) . ') ' . '-' x 30;
my $tags = $i->{tags};
my @ranked = sort { $tags->{$b} <=> $tags->{$a} || $a cmp $b } keys %$tags;
@ranked = @ranked[0 .. $o->{top} - 1] if @ranked > $o->{top};
my $max = @ranked ? $tags->{$ranked[0]} : 1;
for my $t (@ranked) {
my $bar = '#' x int(30 * $tags->{$t} / $max + 0.5);
printf " %-10s %6s %s\n", "<$t>", commify($tags->{$t}), $bar;
}
say '';

if (@{ $i->{outline} }) {
say '-- Heading outline ' . '-' x 45;
for my $h (@{ $i->{outline} }[0 .. min(19, $#{ $i->{outline} })]) {
my $text = length $h->{text} > 70 ? substr($h->{text}, 0, 67) . '...' : $h->{text};
say ' ' . (' ' x ($h->{level} - 1)) . "h$h->{level} $text";
}
say ' ...' if @{ $i->{outline} } > 20;
say '';
}

my $l = $i->{links};
say '-- Links ' . '-' x 54;
printf "Internal: %d External: %d Other (mailto/tel/etc): %d\n",
scalar @{ $l->{internal} }, scalar @{ $l->{external} }, scalar @{ $l->{other} };
if (@{ $i->{top_external_domains} }) {
say 'Top external domains:';
my @d = @{ $i->{top_external_domains} };
@d = @d[0 .. $o->{top} - 1] if @d > $o->{top};
printf " %-36s %d\n", $_->{domain}, $_->{links} for @d;
}
if ($o->{links}) {
say 'All internal links:';
say " $_" for @{ $l->{internal} };
say 'All external links:';
say " $_" for @{ $l->{external} };
}
say '';

my $res = $i->{resources};
say '-- Resources ' . '-' x 50;
printf "Images: %d Scripts: %d Stylesheets: %d\n",
scalar @{ $res->{images} }, scalar @{ $res->{scripts} }, scalar @{ $res->{stylesheets} };
say '';
}

sub commify {
my ($n) = @_;
$n = 0 unless defined $n;
1 while $n =~ s/^(\d+)(\d{3})/$1,$2/;
return $n;
}

sub min { $_[0] < $_[1] ? $_[0] : $_[1] }

sub usage {
my ($code, $msg) = @_;
my $fh = $code ? \*STDERR : \*STDOUT;
print {$fh} "$msg\n\n" if $msg;
print {$fh} <<'USAGE';
Usage: pagesource.pl [options] [URL]

--url URL page to fetch (https:// is assumed if omitted)
--file PATH analyze a local HTML file instead of fetching
--base URL base URL used to resolve links when using --file
--out PATH save the raw source to PATH
--print also print the raw source to stdout
--links list every internal and external link
--top N rows in the tag/domain tables (default 10)
--json emit the analysis as JSON instead of a text report
--agent STRING User-Agent header
--timeout SECS network timeout (default 15)
--retries N attempts for 5xx/connection errors (default 3)
-h, --help show this help
USAGE
exit $code;
}

Hot russian chick

 


Thursday, October 29, 2026

this is what im most proud of

#!/usr/bin/env python3
"""
tor_access.py - Access the web (including .onion sites) through Tor.

Two ways to use it:

1. Route Python requests through Tor Browser / the Tor daemon:
       python tor_access.py check
       python tor_access.py fetch https://example.com
       python tor_access.py fetch http://<address>.onion

2. Launch the Tor Browser application itself:
       python tor_access.py launch --path "/path/to/tor-browser"

Requirements:
    pip install requests[socks]

Tor must be running:
    - Tor Browser running (SOCKS proxy on 127.0.0.1:9150), or
    - The standalone tor service (SOCKS proxy on 127.0.0.1:9050)
"""

import argparse
import os
import platform
import socket
import subprocess
import sys

import requests

TOR_HOST = "127.0.0.1"
TOR_PORTS = (9150, 9050)  # 9150 = Tor Browser, 9050 = tor daemon


def find_tor_port():
    """Return the first SOCKS port where Tor is listening, or None."""
    for port in TOR_PORTS:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.settimeout(1)
            if s.connect_ex((TOR_HOST, port)) == 0:
                return port
    return None


def tor_session():
    """Create a requests session that sends all traffic through Tor."""
    port = find_tor_port()
    if port is None:
        sys.exit(
            "Tor is not running. Start Tor Browser (port 9150) "
            "or the tor service (port 9050) and try again."
        )
    # socks5h = DNS resolution happens inside Tor (needed for .onion, avoids DNS leaks)
    proxy = f"socks5h://{TOR_HOST}:{port}"
    session = requests.Session()
    session.proxies = {"http": proxy, "https": proxy}
    session.headers["User-Agent"] = (
        "Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0"
    )
    print(f"[+] Using Tor SOCKS proxy on port {port}")
    return session


def check_tor():
    """Verify that traffic is actually exiting through the Tor network."""
    session = tor_session()
    r = session.get("https://check.torproject.org/api/ip", timeout=60)
    r.raise_for_status()
    data = r.json()
    if data.get("IsTor"):
        print(f"[+] Connected through Tor. Exit IP: {data.get('IP')}")
    else:
        print(f"[-] Not using Tor. IP: {data.get('IP')}")


def fetch(url):
    """Fetch a URL through Tor and print basic info plus a text preview."""
    session = tor_session()
    r = session.get(url, timeout=90)
    print(f"[+] Status: {r.status_code}")
    print(f"[+] Content-Type: {r.headers.get('Content-Type')}")
    print("-" * 60)
    print(r.text[:2000])


def launch_browser(path=None):
    """Launch the Tor Browser application."""
    system = platform.system()
    candidates = []
    if path:
        candidates.append(path)
    home = os.path.expanduser("~")
    if system == "Windows":
        candidates += [
            os.path.join(home, "Desktop", "Tor Browser", "Browser", "firefox.exe"),
            r"C:\Program Files\Tor Browser\Browser\firefox.exe",
        ]
    elif system == "Darwin":
        candidates += ["/Applications/Tor Browser.app/Contents/MacOS/firefox"]
    else:
        candidates += [
            os.path.join(home, "tor-browser", "Browser", "start-tor-browser"),
            os.path.join(home, ".local/share/torbrowser/tbb/x86_64/tor-browser/Browser/start-tor-browser"),
            "/usr/bin/torbrowser-launcher",
        ]

    for c in candidates:
        # Allow pointing at the install folder instead of the executable
        if os.path.isdir(c):
            for name in ("start-tor-browser", "firefox.exe", "firefox"):
                for sub in ("", "Browser"):
                    p = os.path.join(c, sub, name)
                    if os.path.isfile(p):
                        c = p
                        break
        if os.path.isfile(c):
            print(f"[+] Launching Tor Browser: {c}")
            subprocess.Popen([c], cwd=os.path.dirname(c))
            return
    sys.exit("Could not find Tor Browser. Pass its location with --path.")


def main():
    parser = argparse.ArgumentParser(description="Access Tor from Python")
    sub = parser.add_subparsers(dest="cmd", required=True)

    sub.add_parser("check", help="Verify traffic goes through Tor")

    f = sub.add_parser("fetch", help="Fetch a URL through Tor")
    f.add_argument("url")

    l = sub.add_parser("launch", help="Launch the Tor Browser app")
    l.add_argument("--path", help="Path to Tor Browser folder or executable")

    args = parser.parse_args()
    if args.cmd == "check":
        check_tor()
    elif args.cmd == "fetch":
        fetch(args.url)
    elif args.cmd == "launch":
        launch_browser(args.path)


if __name__ == "__main__":
    main()



tor_access.py check

tor_access.py fetch <url>

tor_access.py launch --path "<Tor Browser folder>"



this no one will understand i promise

  #!/usr/bin/env bash # pyreg.sh: registry-style store in pure bash. # # Here the directory tree IS the registry: keys are directories under...