3

I want one of machine have a remote control alarm running that can be triggered by any remote machine. More precisely

  • Machine A is running the service in the background
  • Any remote machine B can send a packet to machine A to trigger the alarm (a command called alarm)

How would you suggest do do it?

I would use nc:

  • Service on machine A:

    nc -l 1111; alarm
    
  • Machine B triggers the alarm with

    nc <IP of machine A> 1111
    

I can also write some python to open a socket...

user123456
  • 4,758
  • 11
  • 52
  • 78
  • 2
    Google for "port knocking", or write an [UDP client server](https://wiki.python.org/moin/UdpCommunication) in Python. – Satō Katsura Mar 08 '17 at 13:42
  • if it's going to be UDP, you could just use `net-snmp`. Have `snmpd` listening for traps on maching A, and machine B..X can send snmp traps to trigger the alarm. – Tim Kennedy Mar 08 '17 at 14:49

1 Answers1

1

Consider this Python3 example.

Server A:

#!/usr/bin/env python3
# coding=utf8

from subprocess import check_call
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler

# Restrict to a particular path
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/JRK75WAS5GMOHA9WV8GA48CJ3SG7CHXL',)

# Create server
server = SimpleXMLRPCServer(
    ('127.0.0.1', 8888),
    requestHandler=RequestHandler)

# Register your function
server.register_function(check_call, 'call')

# Run the server's main loop
server.serve_forever()

Server B:

#!/usr/bin/env python3
# coding=utf8

import xmlrpc.client

host = '127.0.0.1'
port = 8888
path = 'JRK75WAS5GMOHA9WV8GA48CJ3SG7CHXL'

# Create client
s = xmlrpc.client.ServerProxy('http://{}:{}/{}'.format(host, port, path))

# Call your function on the remote server
s.call(['alarm'])
NarūnasK
  • 2,276
  • 4
  • 25
  • 35