Initial commit
This commit is contained in:
commit
66599f38fe
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
*.swp
|
||||
venv
|
||||
*.pyc
|
||||
__pycache__/*
|
||||
__pycache__
|
||||
*.wpr
|
||||
*.log
|
||||
.idea
|
48
main.py
Normal file
48
main.py
Normal file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
import socket
|
||||
import time
|
||||
import fcntl
|
||||
import struct
|
||||
|
||||
|
||||
def get_ip_address(ifname):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15].encode()))[20:24])
|
||||
|
||||
|
||||
def get_uptime():
|
||||
with open('/proc/uptime', 'r') as f:
|
||||
uptime_seconds = float(f.readline().split()[0])
|
||||
|
||||
return uptime_seconds
|
||||
|
||||
|
||||
def main():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"eth0")
|
||||
|
||||
print("Beaconing...") # or something, idk i don't do english
|
||||
while True:
|
||||
|
||||
ipaddr = ""
|
||||
try:
|
||||
ipaddr = get_ip_address("eth0")
|
||||
except:
|
||||
pass
|
||||
|
||||
message = b"BIRBOX|" + ipaddr.encode() + b"|" + str(int(get_uptime())).encode()
|
||||
|
||||
sock.sendto(message, ('<broadcast>', 6969))
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Starting beacon...")
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
print("Beacon stopped.")
|
Loading…
Reference in New Issue
Block a user