Skip to content

Instantly share code, notes, and snippets.

@5kr1p7
Last active August 19, 2022 23:14
Show Gist options
  • Save 5kr1p7/fa06df048e4e9ade0ecd5bc84674ed64 to your computer and use it in GitHub Desktop.
Save 5kr1p7/fa06df048e4e9ade0ecd5bc84674ed64 to your computer and use it in GitHub Desktop.
Send messages to device from https://ipv6board.best-practice.se
#!/usr/bin/python3
import sys
import os
def ascii_to_code(message):
"""Convert chars to ASCII HEX codes"""
ascii = ''
for char in message.center(8, ' '): # Center align string
ascii += format(ord(char), "x") # Get chars ASCII hex codes
return [(ascii[i:i+4]) for i in range(0, len(ascii), 4)] # Return 4-chars array
def ping6(address, method='web'):
"""Run ping from ssh host or web service"""
if method == 'ssh': # Run SSH command via IPv6 configured network device or server
os.system('ssh admin@mikrotik.address.com "/ping count=1 '+address+'" > /dev/null') # Run ping from MikroTik
else: # Other method (web services)
address = address.replace(':', '%3A') # Replace ":" in URL for cURL
os.system("curl -s 'http://lg.citytelecom.ru/' -H 'Connection: keep-alive' -H 'Origin: http://lg.citytelecom.ru' -H 'Referer: http://lg.citytelecom.ru/' --data 'query=ping&protocol=IPv4&addr="+address+"&router=rt1.msk' --compressed --insecure > /dev/null")
def get_ip(message='Hello!'):
"""Generate IP address to ping"""
return '2001:6b0:1001:105:'+':'.join( ascii_to_code(message) )
#----------------------------------
debug = False # Debug flag
messages = sys.argv[1:] # Get arguments (message lines)
for message in messages:
message = message[:8] # Short the line to 8 chars (max line length for display)
if debug is True: # Print debug info
print(message) # Print shorten message
print('ping -6 -c1 -W1 '+get_ip(message)) # Print generated IP address
ping6(get_ip(message), 'web') # Run ping for message line
@5kr1p7
Copy link
Author

5kr1p7 commented Aug 15, 2019

Clock:

while :; do ./ipv6board_sender.py " " $(echo -n `date -u '+%H:%M:'` && date -u '+%S' --date="+12 seconds") " (UTC) "; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment