0 Replies Latest reply on Dec 5, 2011 2:43 PM by andrep1

    wake on lan tool that gets its data from ePO




      I've been working on this for a while now and before I post this code in the ePO tools forum, I wanted to post a usable version of the tool for some testing and feedback.

      The tool currently takes as input the system name, does a query to epo based on that exact name, gets the required information for a magic packet and then sends it away for the wake up. The tool should work with the packet being sent fromt the same or from a different subnet.


      Questions I have:

      -Do you want to be prompted for a password instead of having it in the code?

      -How should the "wake up one" vs "wake up many" interface should be to work for you ?



      The tool requires the  IPcalc library available at the following:


      Copy the .py file into you python lib directory and that should be it.



      Copy the code below and modify the lines in red with the correct value for your environment. Save to wolepo.py

      execute the code and test it...


      Note that there is basically no error checking and no IPv6 handling...


      # wolepo.py
      # Wake-up script to turn on device using magic packet
      # Enter a device name and the required information will be gathered
      # from your ePO server to send a amgic packet to wake up the device.
      # André Parent, 2011
      # This uses module ipcalc.py available at
      # http://pypi.python.org/pypi/ipcalc/
      # -copy ipcalc.py file to lib directory

      import mcafee, ipcalc, re, string
      #import subprocess

      # Wake-On-LAN
      # Copyright (C) 2002 by Micro Systems Marc Balmer
      # Written by Marc Balmer, marc@msys.ch, http://www.msys.ch/
      # This code is free software under the GPL

      import struct, socket
      def WakeOnLan(ethernet_address, broadcast_address ):
          # Construct a six-byte hardware address
          addr_byte = ethernet_address.split(':')
          hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16),
          int(addr_byte[1], 16),
          int(addr_byte[2], 16),
          int(addr_byte[3], 16),
          int(addr_byte[4], 16),
          int(addr_byte[5], 16))
          # Build the Wake-On-LAN "Magic Packet"...
          msg = '\xff' * 6 + hw_addr * 16
          print msg
          # ...and send it to the broadcast address using UDP
          s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
          s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
          s.sendto(msg, (broadcast_address, 7)) #try port 7
          s.sendto(msg, (broadcast_address, 9)) #try port 9
      # Set your own values here
      epoServerName   = 'server'
      epoServerPort   = 'port'
      epoUserName     = 'username'
      epoUserPassword = 'password'


      device=raw_input("Enter system name of the device to wake-up:")

      mc=mcafee.client(epoServerName, epoServerPort, epoUserName, epoUserPassword)

      #Get data required from ePO Server
      print ("Querying ePO "+device)
      systems = mc.core.executeQuery(target="EPOLeafNode",
                select="(select EPOComputerProperties.ComputerName EPOComputerProperties.IPV6 EPOComputerProperties.NetAddress EPOComputerProperties.IPSubnet EPOComputerProperties.IPSubnetMask)",
                where="(where (and (eq EPOComputerProperties.ComputerName \""+device+"\") (stateEq EPOLeadNode.ManagedState \"managed\" )))"

      for system in systems:
          name, mac, ipaddr = (system["EPOComputerProperties.ComputerName"], system["EPOComputerProperties.NetAddress"],
          #convert mac to 00:00:00:00:00:00 format
          blocks = [mac[x:x+2] for x in xrange(0, len(mac), 2)]
          mac = ':'.join(blocks)
          #get subnet address and convert to IPv4 format
          subnetv6= ipcalc.IP(re.sub(oldprefix, newprefix, system["EPOComputerProperties.IPSubnet"]))
          subnetv4= str(subnetv6.to_ipv4())
          maskv6= ipcalc.IP(re.sub(oldprefix, newprefix, system["EPOComputerProperties.IPSubnetMask"]))
          maskv4= string.count(maskv6.bin(),'1')
          oBroadcast=ipcalc.Network(subnetv4, maskv4)

          print "Waking up device: "+name+" with MAC "+str(mac)+" broadcasting to "+str(broadcast)
          WakeOnLan(str(mac), str(broadcast))