/*** void Main(string[] args) * * Parameters: * * args - command line strings * * * Return Values: * None * * Errors: * * * Description: * * Main entrypoint to the program. * * if only a port number, it is assumed to be a server side (listening) code * if only a MAC, then it is an immediate broadcast of the Magic Packet. * Otherwise as a client an IP address, Port number, and MAC value is expected. * See help screen info below. * ------------------------------------------------------------ */ static void Main(string[] args) { IPINFO ipInfo = new IPINFO(); bool fServer = false; bool fClient = false; bool fBroadCast = false; bool fQuit = false; RemoteWol remoteWol = new RemoteWol(); Thread thrdListen = new Thread(remoteWol.ListenForWOLRequest); Console.WriteLine("RemoteWol Version {0}", typeof(RemoteWol).Assembly.GetName().Version.ToString()); Console.WriteLine("Keith Vogel, Copywrite 2011"); Console.WriteLine(""); // if we only have only 1 parameter, then we have either a port number and we are server // or we have a MAC and we are to send a Magic Packet broadcast to the MAC if (args.Length == 1) { // if this is a Mac Address, a valid port number would never be 6 bytes long. if (args[0].Length == 12 || args[0].Length == 17) { fBroadCast = remoteWol.GetMac(args[0], ipInfo); ; } else { fServer = remoteWol.GetPort(args[0], ipInfo); } } #if QUIT // else if we have IP and Port but no MAC, this means to terminate the server side. else if (args.Length == 2) { // Get the IP if (remoteWol.GetIPAddress(args[0], ipInfo)) { // now get the port fQuit = remoteWol.GetPort(args[1], ipInfo); } } #endif // else if we have IP, Port, and MAC, we are sending a WOL request else if (args.Length == 3) { // Get the IP if (remoteWol.GetIPAddress(args[0], ipInfo)) { // now get the port if (remoteWol.GetPort(args[1], ipInfo)) { // and finally get the MAC fClient = remoteWol.GetMac(args[2], ipInfo); // if we want both server and client to run. fServer = (fRunServerAndClient && fClient); } } } // if we are to run the server if (fServer) { // this starts a thread and will return immediately thrdListen.Start(ipInfo); // this is so we don't start the client too fast if the client is to be started as well. Thread.Sleep(5000); // give it sometime to start the server } // if we are to run the client if (fClient || fQuit) { remoteWol.SenderWOLRequest(ipInfo); } // if we are to broadcast the Magic Packet if (fBroadCast) { if (remoteWol.BroadCast(ipInfo.mac)) { Console.WriteLine("Magic Packet Sent"); } else { Console.WriteLine("Unable to send Magic Packet"); } } // This is the Help Screen Info // if we are to do nothing, print help. if (!fServer && !fClient && !fBroadCast && !fQuit) { Console.WriteLine("Server:\t\tRemoteWol Port"); Console.WriteLine("Client:\t\tRemoteWol ServerURL Port MAC"); Console.WriteLine("WOL Broadcast:\tRemoteWol MAC"); #if QUIT Console.WriteLine("Quit Server:\tRemoteWol ServerURL Port"); #endif Console.WriteLine(""); Console.WriteLine("Where:"); Console.WriteLine(""); Console.WriteLine(" ServerURL:\tis the IP/DNS Name of the server to transmit the WOL."); Console.WriteLine(" Port:\tis the decimal port number the server is listening on."); Console.WriteLine(" MAC:\tis the 12 hex character MAC Address of the machine to wake up,"); Console.WriteLine(" \t\t colons \":\" and dashes \"-\" are allowed between hex bytes."); Console.WriteLine(""); Console.WriteLine("Example:"); Console.WriteLine(""); Console.WriteLine(" RemoteWol mynetwork.com 2000 65:24:EF:04:23:FC"); return; } }
/*** void Main(string[] args) * * Parameters: * * args - command line strings * * * Return Values: * None * * Errors: * * * Description: * * Main entrypoint to the program. * * if only a port number, it is assumed to be a server side (listening) code * if only a MAC, then it is an immediate broadcast of the Magic Packet. * Otherwise as a client an IP address, Port number, and MAC value is expected. * See help screen info below. * ------------------------------------------------------------ */ static void Main(string[] args) { IPINFO ipInfo = new IPINFO(); bool fServer = false; bool fClient = false; bool fBroadCast = false; bool fQuit = false; RemoteWol remoteWol = new RemoteWol(); Thread thrdListen = new Thread(remoteWol.ListenForWOLRequest); Console.WriteLine("RemoteWol Version {0}", typeof(RemoteWol).Assembly.GetName().Version.ToString()); Console.WriteLine("Keith Vogel, Copywrite 2011"); Console.WriteLine(""); // if we only have only 1 parameter, then we have either a port number and we are server // or we have a MAC and we are to send a Magic Packet broadcast to the MAC if (args.Length == 1) { // if this is a Mac Address, a valid port number would never be 6 bytes long. if (args[0].Length == 12 || args[0].Length == 17) { fBroadCast = remoteWol.GetMac(args[0], ipInfo);; } else { fServer = remoteWol.GetPort(args[0], ipInfo); } } #if QUIT // else if we have IP and Port but no MAC, this means to terminate the server side. else if (args.Length == 2) { // Get the IP if (remoteWol.GetIPAddress(args[0], ipInfo)) { // now get the port fQuit = remoteWol.GetPort(args[1], ipInfo); } } #endif // else if we have IP, Port, and MAC, we are sending a WOL request else if (args.Length == 3) { // Get the IP if (remoteWol.GetIPAddress(args[0], ipInfo)) { // now get the port if (remoteWol.GetPort(args[1], ipInfo)) { // and finally get the MAC fClient = remoteWol.GetMac(args[2], ipInfo); // if we want both server and client to run. fServer = (fRunServerAndClient && fClient); } } } // if we are to run the server if (fServer) { // this starts a thread and will return immediately thrdListen.Start(ipInfo); // this is so we don't start the client too fast if the client is to be started as well. Thread.Sleep(5000); // give it sometime to start the server } // if we are to run the client if (fClient || fQuit) { remoteWol.SenderWOLRequest(ipInfo); } // if we are to broadcast the Magic Packet if (fBroadCast) { if (remoteWol.BroadCast(ipInfo.mac)) { Console.WriteLine("Magic Packet Sent"); } else { Console.WriteLine("Unable to send Magic Packet"); } } // This is the Help Screen Info // if we are to do nothing, print help. if (!fServer && !fClient && !fBroadCast && !fQuit) { Console.WriteLine("Server:\t\tRemoteWol Port"); Console.WriteLine("Client:\t\tRemoteWol ServerURL Port MAC"); Console.WriteLine("WOL Broadcast:\tRemoteWol MAC"); #if QUIT Console.WriteLine("Quit Server:\tRemoteWol ServerURL Port"); #endif Console.WriteLine(""); Console.WriteLine("Where:"); Console.WriteLine(""); Console.WriteLine(" ServerURL:\tis the IP/DNS Name of the server to transmit the WOL."); Console.WriteLine(" Port:\tis the decimal port number the server is listening on."); Console.WriteLine(" MAC:\tis the 12 hex character MAC Address of the machine to wake up,"); Console.WriteLine(" \t\t colons \":\" and dashes \"-\" are allowed between hex bytes."); Console.WriteLine(""); Console.WriteLine("Example:"); Console.WriteLine(""); Console.WriteLine(" RemoteWol mynetwork.com 2000 65:24:EF:04:23:FC"); return; } }