Home AMX User Forum NetLinx Studio

Controlling the Master from Batch Files

I'm trying to see if it's possible to control a master from my computer with simple batch files. I realize, of course, that I can use telnet or webcontrol, but I'd like a quick method of rebooting a controller, or calling up a function/call without logging into anything. Nothing flashy needed.

It makes sense that I can use IP_Client_Open to set up communications between the master and the PC. And the data_event -> string section of the code should make it easy to call up functions based on incoming strings. But I don't know how exactly to send a string to the master over the network.

Anyone tried this, before?

Comments

  • jweatherjweather Posts: 320
    You will probably need a small utility like netcat to make it easy to connect and send things from a batch file. Then you can send commands with statements like "echo foo | netcat 10.1.2.3 8001" in a batch file.
  • Scripted Terminal Emulators

    Try looking at SecureCRT from VanDyke Software. It supports telnet, SSH, serial, and others. You can script it with VBScript, JScript, PerlScript, and Python. I've used it for a while now and I love it. The same company makes SecureFX which is a file-transfer software for FTP, SFTP, and others. It comes with a utility SFXCL that can batch script file transfers, but can't use the advanced scripting that SecureCRT can.

    There's also Indigo from shadeBlue. I only briefly used it due to it being a bit crashy, but it too does scripting, though I believe only VB, and has some pretty neat built in features that allow for "on the fly" scripting with a user-defined command library, variable library, and "command repeater". It has more "nifty" features and eye-candy than SecureCRT, which I assume is why it would crash a bit more. Sometimes simpler is better.

    Enjoy!
    -Nick

    P.S. There's a new version in beta for Indigo. I haven't tried it.
  • Good advice from both of you, thanks. This might be more trouble than it's worth, but I think I'll love it if I get it to work. I'll try and update this if I get anywhere, but progress is slow since I'm working on other projects.

    Any more brainstorming out there?
  • jjamesjjames Posts: 2,908
    What about PowerShell? You can write a quick script that'll connect to the supplied master's IP via ICSP and shoot a reboot command.

    Edit:

    Finished, tested and working . . . this assumes:
    1) Device 5001 exists on the system, as that is the "source" device.
    2) ICSP Encryption is OFF

    Powershell Script:
    if ($args.Length -ne 1)
    {
        throw "No IP address passed, please pass IP parameter"
    }
    $IpAddress= $args[0]
    
    $client = new-Object System.Net.Sockets.TCPClient
    $client.Connect($IpAddress,1319)
    
    if($client.Connected)
    {
        $stream = $client.GetStream()
        [System.Byte[]] $cmd = 0x02, 0x00, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x89, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x01, 0x02, 0x12, 0x00, 0x00, 0xc9
        $stream.Write($cmd,0,$cmd.length)
        $stream.Close(1)
        $client.Close()
    }
    

    Batch file - substitute the name of the PS file with your own and 10.24.42.99 with the IP of your master.
    powershell "C:\RebootMaster.ps1" 10.24.42.99
    

    As a quick side note, this is the first time I've done anything with PowerShell - and you know what? Thanks for making me venture into it. Seems like a handy scripting service, especially being familiar with .Net.
  • Wow, that's some impressive work, there. I'm not familiar with .net, but I think I can monkey around with your example and get it to work. This is amazing.
  • jjamesjjames Posts: 2,908
    Shouldn't have to change too much, except if you wanted to add in some catches or whatnot. It should work as advertise - if you've got PowerShell installed, which I believe comes standard with Vista & 7? Might need to be installed on XP - not sure.
  • I understand. But I may modify it to do other things. It shouldn't be too difficult, because you did the hard part. Sometimes I feel guilty when I just ask smarter people how to do things.
  • jjamesjjames Posts: 2,908
    I understand. But I may modify it to do other things. It shouldn't be too difficult, because you did the hard part. Sometimes I feel guilty when I just ask smarter people how to do things.
    Have you tried it out? Do you have PS installed? I read something about signing certificates and stuff for it to execute on other machines - which is why I just posted the code.

    What other things? If you understand AMX's ICSP, you could do a lot, but honestly, I wouldn't waste my time. I'd rather write a full-boat .Net program to do what I wanted (which is what I did.)

    Anyway, have fun & enjoy!
  • jimmywjimmyw Posts: 112
    This gets me thinking about something I wanted to do many years ago, I had a PDF that documented ICSP years ago that I cant seem to find now, anyone have a copy?
  • jjamesjjames Posts: 2,908
    You probably had the patent, which is floating around out there on the world wide web.

    Speaking of ICSP - I find this very interesting....
    http://findarticles.com/p/articles/mi_m0EIN/is_1999_June_10/ai_54852374/
    Far from being a "closed" protocol, ICSP is an open standard and has been adopted by nearly 100 equipment manufacturers. ICSP products can communicate directly to the NetLinx system, eliminating the need for additional interface peripherals.

    Keep in mind, AMX has never released their encryption algorithm, you'll have to dig deep for that. I'm not saying, I'm just sayin'.
  • jimmywjimmyw Posts: 112
    I have never had any interest in eICSP. I am going to have to go through my old hard drives to see if I found it, someone took the patent doc and rewrote it in a more logical fashion, it also had data on Axlink protocol.
  • jjamesjjames Posts: 2,908
    jimmyw wrote: »
    I have never had any interest in eICSP. I am going to have to go through my old hard drives to see if I found it, someone took the patent doc and rewrote it in a more logical fashion, it also had data on Axlink protocol.
    I started to do this to help along in the rewrite process of my library - but stopped.

    Would be interesting to see it though.
  • The problem is that I don't know anything about .Net. I'm a hardware installer who got into AMX to broaden my skills, but I'm not a programmer, by trade, outside of AMX programming. Maybe I should be.
  • jjamesjjames Posts: 2,908
    I taught piano and was majoring in performance and music education before this . . . anything is possible. ;)
  • OK, I finally tested this (my car broke down in Houston many days ago and I've been away from things), and it works. The only thing I had to do was enable the running of PowerShell scripts on my computer. This is pretty great.

    Would I be correct in assuming that the long system byte is the hexadecimal version of the reboot command? Should I be able to change that to some other command to do other things?
  • jjamesjjames Posts: 2,908
    Would I be correct in assuming that the long system byte is the hexadecimal version of the reboot command? Should I be able to change that to some other command to do other things?

    Yes and no. It's the ICSP command to reboot a device. You'd need to read up on the ICSP patent to know what to change.

    I cannot help with that though - sorry.
  • I see - now, I know where to start looking. Thanks!
  • I just noticed that my system isn't doesn't have a 5001 address - but this still works!
  • jjamesjjames Posts: 2,908
    Interesting, I didn't think the system would respond to certain commands from a device that wasn't online. Good to know.

    Glad it's working.


    Sent from my iPhone using Tapatalk
Sign In or Register to comment.