• invalidusernamelol [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    7
    ·
    edit-2
    1 month ago
    #!/usr/bin/env python
    
    import socket
    
    class Finger:
        def __init__(self, host: str) -> None:
            self.__host = host
    
        def __getitem__(self, user: str) -> str:
            with socket.create_connection((self.__host, 79)) as sock:
                sock.send(user.encode('ascii') + b'\r\n')
                data = b''
                while incoming := sock.recv(1024):
                    data += incoming
                return data.decode(encoding='utf-8', errors='replace')
    
        def __iter__(self):
            nxt = ['']
            while nxt:
                next_user = nxt.pop()
                msg = self[next_user]
                yield msg
                next_users = [
                    handle.split()[-1][:-1]
                    for handle in msg.split(self.__host)
                    if handle.endswith('@')
                ]
                nxt.extend(next_users)
            yield '--EOF--'
    
    
    def main():
        happy = Finger('happynetbox.com')
        feed = iter(happy)
        print(next(feed))
        while True:
            command = input()
            if command in ('exit', 'quit', 'stop', 'done'):
                break
            elif command:
                print(happy[command])
            else:
                print(next(feed))
    
    
    if __name__ == '__main__':
        main()
    

    I love how simple this protocol is. You can just rawdog a socket and jam bytes into it. This should let you doomscroll happynetbox lol.

    Note: whitespace is allowed in usernames (technically any ASCII characters, it’s up to the server admin to limit them, and happynetbox doesn’t lol). So there’s no good way for me to detect a username with whitespace and you’ll just get bumped to a .plan that recommends another user which keeps the chain going.