 |
|
 |
I have this working in a Wake on Wan set-up
|
|
|
|
 |
|
 |
Yo dude, I've downloaded i don't know how much Wake on LAN codes, but none om 'em worked, until I stumbled upon yours.
Big for your code, and thank you sooo much for helping me out!
Cheers!
|
|
|
|
 |
|
|
 |
|
 |
Hi.
Nice work, though i'm getting a no response.
I have a mac 000D9D91825B on a external machine within the network, it's turned off, i'm trying both their is no response..
What do I do?
Regards,
Chr
|
|
|
|
 |
|
 |
You are using conflicting terminology in your query. An "external machine within the network"... Which is it?
Same Subnet
If you mean a different machine on the same subnet (i.e. behind the same router):
1. Verify that the MAC address you have is correct.
2. Verify that the machine you're trying to wake supports Wake on LAN ("WOL") functionality:
2A. BIOS Settings
Go into the machine's BIOS and look for a setting that enables WOL.
2B. Is Your Power Supply Compatible?
Note that your machine's power supply must also support this capability; if your power supply does not have its own "master" on/off switch, it's likely that it's not compatible. Modern power supplies supply a trickle voltage to the computer's motherboard (in "active off" mode); this is routed to the Ethernet adapter, among other things.
2C. Is Wake On LAN Configured in Windows (Windows XP assumed below)
a) In Windows, go into Control Panel & bring up Network Connections.
b) Right-click the Network Adapter corresponding to the MAC address you're trying to wake, & click "Properties".
c) In the Properties dialog, click the "Configure..." button (next to the adapter name).
d) In the "Connection Properties" dialog, look for a Power Management (or similarly named) tab. (This may or may not be there and the name will vary, depending on the manufacturer of your Ethernet adapter & the driver you have installed.)
e) If you do have a Power Management tab, look for options that enable/disable any of the following:
- "Wake on Directed Packet"
- "Wake on Magic Packet"
- "Wake on Magic Packet from power off state"
- "Wake on Link"
These are what I have for an Intel PRO/1000 Ethernet adapter on my machine. You would need to enable the 2 Wake on Magic Packet options (I leave the other 2 disabled).
2D. Note also that for certain add-in Ethernet adapters (PCI) and mother boards you may need to connect a 3-wire "WOL Cable" (from header on card to header on motherboard) for the WOL Capability to work. You would generally find this on really old cards & motherboards (more than 5 years old).
Finally, a note about states:
S1 = On (Operational)
S3 = Standby (enable "Wake on Magic Packet" to allow wakeup from this state)
S5 = Active Off (enable "Wake on Magic Packet from power off state" to allow wakeup from this state)
Different Subnet
If you mean a machine on a different subnet and your magic packet has to be passed outside your local router, I doubt that this is possible. I have read elsewhere that routers do not forward broadcast packets. If it's a router that you control in your own domain, you *may* be able to configure it to do so - someone else would need to comment on this possibility.
|
|
|
|
 |
|
 |
Some routers will pass what is called a directed broadcast. We use Wake on Lan extensively where I work and have made no special changes to our routers to pass broadcasts. You have to figure out what the broadcast address for the subnet you are sending to is then send to that address. For us the simple convertIP method works. Our routers think it is a regular IP Address and route it to the correct subnet then send it to all machines on that subnet(the last octet being 255).The machines whose Mac is sent wakes up the rest ignore the broadcast. This may not always work but its worth a try. Code snippet:
public void SendWakeUp(string MachineName, string IPAddress, string MacAddress)
{
IPAddress WOLIPAddress = convertIP(IPAddress); //Convert to system broadcast IP
byte[] WOLMacAddr = Mac2Byte(MacAddress);// Convertmac address string to byte array
byte[] WOLPayLoad = CreatePayload(WOLMacAddr);// create a byte array payload
IPEndPoint WOLEndPoint = new IPEndPoint(WOLIPAddress, 7); //Create an Ip Endpoint
int Sucess = SendUDP(WOLPayLoad, WOLEndPoint);
}
public IPAddress convertIP(string _IPAddress)
{
string BroadcastAddress = "";
string[] Octets = _IPAddress.Split(new Char[] { '.' });
Octets[3] = "255";
BroadcastAddress = Octets[0] + "." + Octets[1] + "." + Octets[2] + "." + Octets[3];
System.Net.IPAddress wolIPAddr = IPAddress.Parse(BroadcastAddress);
return wolIPAddr;
}
protected static byte[] Mac2Byte(string strMacAddress)
{
string macAddr;
byte[] macBytes = new byte[BYTELENGHT];
//remove all non 0-9, A-F, a-f characters
macAddr = Regex.Replace(strMacAddress, @"[^0-9A-Fa-f]", "");
//check if it is now a valid mac adress
if (!(macAddr.Length == BYTELENGHT * 2))
throw new ArgumentException("Mac Adress must be " + (BYTELENGHT * 2).ToString() + " digits of 0-9, A-F, a-f characters in length.");
string hex;
for (int i = 0; i < macBytes.Length; i++)
{
hex = new String(new Char[] { macAddr[i * 2], macAddr[i * 2 + 1] });
macBytes[(i)] = byte.Parse(hex, System.Globalization.NumberStyles.HexNumber);
}
return macBytes;
}
protected static byte[] CreatePayload(byte[] macAddress)
{
byte[] payloadData = new byte[HEADER + MAGICPACKETLENGTH * BYTELENGHT];
for (int i = 0; i < HEADER; i++)
{
payloadData[i] = byte.Parse("FF", System.Globalization.NumberStyles.HexNumber);
}
for (int i = 0; i < MAGICPACKETLENGTH; i++)
{
for (int j = 0; j < BYTELENGHT; j++)
{
payloadData[((i * BYTELENGHT) + j) + HEADER] = macAddress[j];
}
}
return payloadData;
}
protected static int SendUDP(byte[] Payload, IPEndPoint EndPoint)
{
int byteSend;
//create a new client socket...
Socket socketClient = new Socket(EndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
try
{
//open connection...
socketClient.Connect(EndPoint);
//send MagicPacket(TM)...
byteSend = socketClient.Send(Payload, 0, Payload.Length, SocketFlags.None);
}
catch (SocketException ex)
{
throw ex;
}
finally
{
socketClient.Close();
}
return byteSend;
}
|
|
|
|
 |
|
 |
Thanks for your nice sample!!!
Very good work!
Cu,
devcow
|
|
|
|
 |
|
 |
I used C# Express to test this.
Had to add some directives:
using System.Net; for IPAddress
and
using System.Globalization;for NumberStyles
Thank you for the code, much appreciated.
A.J.
Don't Panic, debug it!
|
|
|
|
 |
|
 |
Hi,can you help me about acting broadcasting in udpclient for chat.
I run this code and give an error in line: client.Connect(new IPAddress(0xffffffff),0x2fff);
This error is:"can not connect to unreachable host".
Please help me to solve this problem!thanks.
|
|
|
|
 |
|
 |
Hi,can you help me about acting broadcasting in udpclient for chat.
I run this code and give an error in line: client.Connect(new IPAddress(0xffffffff),0x2fff);
This error is:"can not connect to unreachable host".
Please help me to solve this problem!thanks.
|
|
|
|
 |
|
 |
Can this logic be implemented in IP broadcasting?
My scenario is that, I have a server and lots of clients. Instead of the server pinging the clients, or the Clients continually pinging the server, I would like all my clients to broadcast single IP packets at regular intervals so that the Server can pick it up and send a confirmation, so that a TCP connection can be established between the two. Also this way, the clients need not have the IP address of the server since I work in a network which has a DHCP server.
Can you help...
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
 |
|
 |
Hi and thanks for the sample, it has helped me to build a console app to remotely wake my own PC in 5 minutes and saved a lot of time (I didn't like the AMD's magic packet program anyway )
I had to add references to these 2 namespaces:
System.Net (IPAddress class)
System.Globalization (NumberStyles enumeration)
rado
;height:1px;" noshade>Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
 |