- update-blacklist creates text file with blocked ips for import to pfBlockerNG on my Router/FW - aprs_sendstatus.py sends a status message to the APRS-IS network and updates the status line of my WX stationmain
parent
19ae5236ea
commit
d363f1cc81
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""sending aprs status packets for my weather station"""
|
||||
|
||||
import aprslib
|
||||
|
||||
|
||||
intervals = (
|
||||
('weeks', 604800), # 60 * 60 * 24 * 7
|
||||
('days', 86400), # 60 * 60 * 24
|
||||
('hours', 3600), # 60 * 60
|
||||
('minutes', 60),
|
||||
('seconds', 1),
|
||||
)
|
||||
|
||||
|
||||
def get_uptime(granularity=2):
|
||||
with open('/proc/uptime', 'r') as u:
|
||||
uptime_seconds = int(float(u.readline().split()[0]))
|
||||
|
||||
return(display_time(uptime_seconds, granularity))
|
||||
|
||||
|
||||
def display_time(seconds, granularity=2):
|
||||
result = []
|
||||
|
||||
for name, count in intervals:
|
||||
value = seconds // count
|
||||
if value:
|
||||
seconds -= value * count
|
||||
if value == 1:
|
||||
name = name.rstrip('s')
|
||||
result.append("{} {}".format(value, name))
|
||||
return ', '.join(result[:granularity])
|
||||
|
||||
|
||||
def test():
|
||||
"""test function"""
|
||||
print('Uptime: ' + get_uptime())
|
||||
|
||||
|
||||
def main():
|
||||
"""main func"""
|
||||
AIS = aprslib.IS("OE7DRT-13", passwd="<actual password>", port=14580)
|
||||
AIS.connect()
|
||||
|
||||
#AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Running for " + get_uptime(2) + " on https://wx.oe7drt.com - happy new year!\r\n")
|
||||
AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Weatherpage: https://wx.oe7drt.com\r\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# or use this one to create only ip addresses
|
||||
# iptables -nL BLACKLIST | tail -n +3 | awk '{ print $4 }' | sort -g
|
||||
|
||||
FILE=/var/www/html/blocked.txt
|
||||
|
||||
/usr/bin/echo -n "# " | /usr/bin/tee $FILE > /dev/null
|
||||
|
||||
/usr/sbin/iptables-nft -nL BLACKLIST | /usr/bin/tail -n +3 | /usr/bin/wc -l | \
|
||||
/usr/bin/tr -d "\n" | /usr/bin/tee -a $FILE > /dev/null
|
||||
|
||||
/usr/bin/echo -en " ips saved.\n# source pkts bytes\n" | /usr/bin/tee -a $FILE > /dev/null
|
||||
|
||||
/usr/sbin/iptables -vnL BLACKLIST | /usr/bin/tail -n +3 | \
|
||||
/usr/bin/awk ' { printf "%-18s %-6s %-6s\n", $8, $1, $2 } ' | /usr/bin/sort -g | \
|
||||
/usr/bin/tee -a $FILE > /dev/null
|
Loading…
Reference in new issue