반응형

매직패킷은 포트 0, 7, 9번중 하나를(요즘은 7,9을 사용. 제조사마다 다르다고 함-이외의 포트를 사용하기도 한다.) 통해 보내지는 브로드캐스트 프레임이다. 이는 여러 프로토콜을 사용하여 보내질 수 있는데, 그중에서 UDP가 가장 자주 쓰인다. 매직패킷은 16진수 FF FF FF FF FF FF의 상수 뒤에 대상 컴퓨터의 맥주소가 16번 반복되는 형태를 가진다.(암호가 설정되어있다면 4, 6자리의 암호도 따라 붙게 된다)

위는 위키(WOL 페이지의 Magic Packet란) 번역한것,


[그림 1] 예제로 보는것이 이해가 더 빠르다.



예전에 매직패킷을 알았을 때에는 도메인 내에서 브로드캐스팅으로 보내지니까 도메인 밖에서는 못보내는줄 알았는데, 지금 위키페디아 보니까 LAN내에 국한되는게 아닐 뿐만 아니라 인터넷 트래픽으로도 WOL(Wake on Lan)이 동작한다고 써있다.

몇가지 원격에서 작동하는 프로그램을 실행해 봤는데, 인터넷 공유기에서 막아버리는지 켜지지 않았다. 기기의 NAT기능이 제대로 작동을 안하기 때문이다. (되고 안되고 지맘대로다-_-) 그래서 우선 원격으로 작동한다는것만 끄적여본다;;;

또한 이번에 검색하면서 여러가지 참고사항들을 알게 되었는데,
1. 포트숫자는 중요하지 않다(브로드캐스트 도메인의 간섭을 최소화 하기 위해 7,9번을 사용하는것) //포트는 아무거나 입력해도 됬었음.
2. 패킷 보내기전에 OS에서 해당 IP/MAC의 ARP 엔트리가 구축되어 있어야 한다. 아님 브로드캐스트 하든가.//브로드캐스트를 이용해야함.
3. Wi-fi 지원 하지 않는다(Ethernet에서만 동작하기 때문에)// wi-fi자체도 문제지만 공유기에서 따로 설정을 해야하는것 같다.
4. BIOS와 네트워크 장치가 서로 호환이 안되면 동작하지 않는다. //BIOS랑 랜카드가 지원안하면 낭패인거;

참고 사이트

1. Wikipedia : Wake-On-Lan
2. c#으로 제작된 프로그램 소스(LAN에서 사용-MAC주소만 입력하는)
3. php로 제작된 프로그램 소스(Lan에서 사용, 여기 댓글이 유용하다)
4. asp.net으로 제작된 프로그램 예제 & 소스(WAN에서 사용-ip, subnet, mac, port 입력)
5. AMD사의 White Paper - "Magic Packet Technologe"(6페이지의 pdf 문서 무지 자세하게 설명됨)


두번째 링크의 소스를 좀 더 편하게 수정하여 잘 사용해왔다.
출처 : http://frontjang.tistory.com/27

'Network' 카테고리의 다른 글

무선공유기 비밀번호 초기값  (0) 2011.08.05
전세계 공개 FTP 서버 리스트  (0) 2009.11.21
Magic Packet  (0) 2009.10.29
paros 3.2.13 - 웹 취약점 분석툴  (0) 2009.08.07
패킷 캡쳐 및 분석 - Wireshark  (0) 2009.07.09
반응형

관리도구 -> 터미널서비스 구성 -> 오른쪽 rdp-tcp 라고 써있는 아이콘에 우클릭하셔서 속성 ->세션텝

에서 설정함.

'OS' 카테고리의 다른 글

Ubuntu 에 APM 설치  (0) 2011.03.19
IIS서버 기본 보안 셋팅  (0) 2009.11.30
비워있지 않는 디렉토리 지우기  (0) 2009.08.29
Linux Command Directory  (0) 2009.08.07
비스타 서비스팩 설치후 테스트모드 뜰 때  (0) 2009.08.07
반응형
/* ether-wake.c: Send a magic packet to wake up sleeping machines. */

static char version_msg[] =
"ether-wake.c: v1.08 3/31/2003 Donald Becker, http://www.scyld.com/";
static char brief_usage_msg[] =
"usage: ether-wake [-i <ifname>] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n"
"   Use '-u' to see the complete set of options.\n";
static char usage_msg[] =
"usage: ether-wake [-i <ifname>] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55

This program generates and transmits a Wake-On-LAN (WOL)
\"Magic Packet\", used for restarting machines that have been
soft-powered-down (ACPI D3-warm state).
It currently generates the standard AMD Magic Packet format, with
an optional password appended.

The single required parameter is the Ethernet MAC (station) address
of the machine to wake or a host ID with known NSS 'ethers' entry.
The MAC address may be found with the 'arp' program while the target
machine is awake.

Options:
  -b Send wake-up packet to the broadcast address.
  -D Increase the debug level.
  -i ifname Use interface IFNAME instead of the default 'eth0'.
  -p <pw>  Append the four or six byte password PW to the packet.
     A password is only required for a few adapter types.
     The password may be specified in ethernet hex format
     or dotted decimal (Internet address)
  -p 00:22:44:66:88:aa
  -p 192.168.1.1
";

/*
This program generates and transmits a Wake-On-LAN (WOL) "Magic Packet",
used for restarting machines that have been soft-powered-down
(ACPI D3-warm state).  It currently generates the standard AMD Magic Packet
format, with an optional password appended.

This software may be used and distributed according to the terms
of the GNU Public License, incorporated herein by reference.
Contact the author for use under other terms.

This source file was originally part of the network tricks package, and
is now distributed to support the Scyld Beowulf system.
Copyright 1999-2003 Donald Becker and Scyld Computing Corporation.

The author may be reached as becker@scyld, or C/O
  Scyld Computing Corporation
  410 Severn Ave., Suite 210
  Annapolis MD 21403

  Notes:
  On some systems dropping root capability allows the process to be
  dumped, traced or debugged.
  If someone traces this program, they get control of a raw socket.
  Linux handles this safely, but beware when porting this program.

  An alternative to needing 'root' is using a UDP broadcast socket, however
  doing so only works with adapters configured for unicast broadcast Rx
  filter.  That configuration consumes more power.
*/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>

#if 0       /* Only exists on some versions. */
#include <ioctls.h>
#endif

#include <sys/socket.h>

#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/if.h>

#include <features.h>
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
#include <net/ethernet.h>
#else
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#endif
#include <netdb.h>
#include <netinet/ether.h>

/* Grrr, no consistency between include versions.
   Enable this if setsockopt() isn't declared with your library. */
#if 0
extern int setsockopt __P ((int __fd, int __level, int __optname,
       __ptr_t __optval, int __optlen));
#else    /* New, correct head files.  */
#include <sys/socket.h>
#endif
#ifdef USE_SENDMSG
#include <iovec.h>
#endif

u_char outpack[1000];
int outpack_sz = 0;
int debug = 0;
u_char wol_passwd[6];
int wol_passwd_sz = 0;

static int opt_no_src_addr = 0, opt_broadcast = 0;

static int get_dest_addr(const char *arg, struct ether_addr *eaddr);
static int get_fill(unsigned char *pkt, struct ether_addr *eaddr);
static int get_wol_pw(const char *optarg);

int main(int argc, char *argv[])
{
char *ifname = "eth0";
int one = 1;    /* True, for socket options. */
int s;      /* Raw socket */
int errflag = 0, verbose = 0, do_version = 0;
int perm_failure = 0;
int i, c, pktsize;
#if defined(PF_PACKET)
struct sockaddr_ll whereto;
#else
struct sockaddr whereto; /* who to wake up */
#endif
struct ether_addr eaddr;

while ((c = getopt(argc, argv, "bDi:p:uvV")) != -1)
  switch (c) {
  case 'b': opt_broadcast ; break;
  case 'D': debug ;   break;
  case 'i': ifname = optarg; break;
  case 'p': get_wol_pw(optarg); break;
  case 'u': printf(usage_msg); return 0;
  case 'v': verbose ;  break;
  case 'V': do_version ;  break;
  case '?':
   errflag ;
  }
if (verbose || do_version)
  printf("%s\n", version_msg);
if (errflag) {
  fprintf(stderr, brief_usage_msg);
  return 3;
}

if (optind == argc) {
  fprintf(stderr, "Specify the Ethernet address as 00:11:22:33:44:55.\n");
  return 3;
}

/* Note: PF_INET, SOCK_DGRAM, IPPROTO_UDP would allow SIOCGIFHWADDR to
    work as non-root, but we need SOCK_PACKET to specify the Ethernet
    destination address. */
#if defined(PF_PACKET)
s = socket(PF_PACKET, SOCK_RAW, 0);
#else
s = socket(AF_INET, SOCK_PACKET, SOCK_PACKET);
#endif
if (s < 0) {
  if (errno == EPERM)
   fprintf(stderr, "ether-wake: This program must be run as root.\n");
  else
   perror("ether-wake: socket");
  perm_failure ;
}
/* Don't revert if debugging allows a normal user to get the raw socket. */
setuid(getuid());

/* We look up the station address before reporting failure so that
    errors may be reported even when run as a normal user.
*/
if (get_dest_addr(argv[optind], &eaddr) != 0)
  return 3;
if (perm_failure && ! debug)
  return 2;

pktsize = get_fill(outpack, &eaddr);

/* Fill in the source address, if possible.
    The code to retrieve the local station address is Linux specific. */
if (! opt_no_src_addr) {
  struct ifreq if_hwaddr;
  unsigned char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data;

  strcpy(if_hwaddr.ifr_name, ifname);
  if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) {
   fprintf(stderr, "SIOCGIFHWADDR on %s failed: %s\n", ifname,
     strerror(errno));
   /* Magic packets still work if our source address is bogus, but
      we fail just to be anal. */
   return 1;
  }
  memcpy(outpack 6, if_hwaddr.ifr_hwaddr.sa_data, 6);

  if (verbose) {
   printf("The hardware address (SIOCGIFHWADDR) of %s is type %d  "
       "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n", ifname,
       if_hwaddr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1],
       hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
  }
}

if (wol_passwd_sz > 0) {
  memcpy(outpack pktsize, wol_passwd, wol_passwd_sz);
  pktsize = wol_passwd_sz;
}

if (verbose > 1) {
  printf("The final packet is: ");
  for (i = 0; i < pktsize; i )
   printf(" %2.2x", outpack[i]);
  printf(".\n");
}

/* This is necessary for broadcasts to work */
if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&one, sizeof(one)) < 0)
  perror("setsockopt: SO_BROADCAST");

#if defined(PF_PACKET)
{
  struct ifreq ifr;
  strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) {
   fprintf(stderr, "SIOCGIFINDEX on %s failed: %s\n", ifname,
     strerror(errno));
   return 1;
  }
  memset(&whereto, 0, sizeof(whereto));
  whereto.sll_family = AF_PACKET;
  whereto.sll_ifindex = ifr.ifr_ifindex;
  /* The manual page incorrectly claims the address must be filled.
     We do so because the code may change to match the docs. */
  whereto.sll_halen = ETH_ALEN;
  memcpy(whereto.sll_addr, outpack, ETH_ALEN);

}
#else
whereto.sa_family = 0;
strcpy(whereto.sa_data, ifname);
#endif

if ((i = sendto(s, outpack, pktsize, 0, (struct sockaddr *)&whereto,
     sizeof(whereto))) < 0)
  perror("sendto");
else if (debug)
  printf("Sendto worked ! %d.\n", i);

#ifdef USE_SEND
if (bind(s, &whereto, sizeof(whereto)) < 0)
  perror("bind");
else if (send(s, outpack, 100, 0) < 0)
  perror("send");
#endif
#ifdef USE_SENDMSG
{
  struct msghdr msghdr;
  struct iovec iovector[1];
  msghdr.msg_name = &whereto;
  msghdr.msg_namelen = sizeof(whereto);
  msghdr.msg_iov = iovector;
  msghdr.msg_iovlen = 1;
  iovector[0].iov_base = outpack;
  iovector[0].iov_len = pktsize;
  if ((i = sendmsg(s, &msghdr, 0)) < 0)
   perror("sendmsg");
  else if (debug)
   printf("sendmsg worked, %d (%d).\n", i, errno);
}
#endif

return 0;
}

/* Convert the host ID string to a MAC address.
   The string may be a
Host name
    IP address string
MAC address string
*/

static int get_dest_addr(const char *hostid, struct ether_addr *eaddr)
{
struct ether_addr *eap;

eap = ether_aton(hostid);
if (eap) {
  *eaddr = *eap;
  if (debug)
   fprintf(stderr, "The target station address is %s.\n",
     ether_ntoa(eaddr));
} else if (ether_hostton(hostid, eaddr) == 0) {
  if (debug)
   fprintf(stderr, "Station address for hostname %s is %s.\n",
     hostid, ether_ntoa(eaddr));
} else {
  (void)fprintf(stderr,
       "ether-wake: The Magic Packet host address must be "
       "specified as\n"
       "  - a station address, 00:11:22:33:44:55, or\n"
       "  - a hostname with a known 'ethers' entry.\n");
  return -1;
}
return 0;
}


static int get_fill(unsigned char *pkt, struct ether_addr *eaddr)
{
int offset, i;
unsigned char *station_addr = eaddr->ether_addr_octet;

if (opt_broadcast)
  memset(pkt 0, 0xff, 6);
else
  memcpy(pkt, station_addr, 6);
memcpy(pkt 6, station_addr, 6);
pkt[12] = 0x08;    /* Or 0x0806 for ARP, 0x8035 for RARP */
pkt[13] = 0x42;
offset = 14;

memset(pkt offset, 0xff, 6);
offset = 6;

for (i = 0; i < 16; i ) {
  memcpy(pkt offset, station_addr, 6);
  offset = 6;
}
if (debug) {
  fprintf(stderr, "Packet is ");
  for (i = 0; i < offset; i )
   fprintf(stderr, " %2.2x", pkt[i]);
  fprintf(stderr, ".\n");
}
return offset;
}

static int get_wol_pw(const char *optarg)
{
int passwd[6];
int byte_cnt;
int i;

byte_cnt = sscanf(optarg, "%2x:%2x:%2x:%2x:%2x:%2x",
       &passwd[0], &passwd[1], &passwd[2],
       &passwd[3], &passwd[4], &passwd[5]);
if (byte_cnt < 4)
  byte_cnt = sscanf(optarg, "%d.%d.%d.%d",
        &passwd[0], &passwd[1], &passwd[2], &passwd[3]);
if (byte_cnt < 4) {
  fprintf(stderr, "Unable to read the Wake-On-LAN password.\n");
  return 0;
}
printf(" The Magic packet password is %2.2x %2.2x %2.2x %2.2x (%d).\n",
     passwd[0], passwd[1], passwd[2], passwd[3], byte_cnt);
for (i = 0; i < byte_cnt; i )
  wol_passwd[i] = passwd[i];
return wol_passwd_sz = byte_cnt;
}

#if 0
{
to = (struct sockaddr_in *)&whereto;
to->sin_family = AF_INET;
if (inet_aton(target, &to->sin_addr)) {
  hostname = target;
}
memset (&sa, 0, sizeof sa);
sa.sa_family = AF_INET;
strncpy (sa.sa_data, interface, sizeof sa.sa_data);
sendto (sock, buf, bufix len, 0, &sa, sizeof sa);
strncpy (sa.sa_data, interface, sizeof sa.sa_data);
#if 1
sendto (sock, buf, bufix len, 0, &sa, sizeof sa);
#else
bind (sock, &sa, sizeof sa);
connect();
send (sock, buf, bufix len, 0);
#endif
}
#endif


/*
* Local variables:
*  compile-command: "gcc -O -Wall -o ether-wake ether-wake.c"
*  c-indent-level: 4
*  c-basic-offset: 4
*  c-indent-level: 4
*  tab-width: 4
* End:
*/




출처 : http://www.scyld.com/expert/wake-on-lan.html

'Programming' 카테고리의 다른 글

Adobe AIR 3 / 기술 사양  (0) 2012.02.06
11월 17일 랩실 C언어 교육  (0) 2009.11.17
WOL c++ sourcecode  (0) 2009.10.29
IE8설치 후 VS에러 패치  (0) 2009.10.14
컴포넌트의 종류  (0) 2009.08.28
반응형

// http://sourceforge.net/projects/wakeonlan/
// WakeOnLan - commandline application to start computers via wake on lan enbaled
// network interface card.
// Author: erik.tornstam@home.se
// Copyright: erik.tornstam@home.se

#include "stdio.h"
#include "iostream.h"
#include "winsock2.h"

#define DEFAULT_BROADCAST "255.255.255.255"
#define DEFAULT_PORT 32767

parse_mac(unsigned char *mac, char *str)
{
    int i;
    int count;
    char c;
    unsigned char val;
    int separator_ok = 1;

    for (i = 0; i < 6; i++) {
  mac[i] = 0;
    }

    for (i = 0; i < 6; i++) {
  count = 0;
  val   = 0;
  do {
   c = toupper(*str++);
   if (c >= '0' && c <= '9')
   {
    val = (val * 16) + (c - '0');
   }
   else if (c >= 'A' && c <= 'F')
   {
    val = (val * 16) + (c - 'A') + 10;
   }
   else if (c == '-' || c == ':')
   {
   if (separator_ok || count-- != 0)
    break;
   }
   else if (c == '\0')
   {
    str--;
    break;
   }
   else
   {
    return 0;
   }
   separator_ok=1;
  } while (++count < 2);

  separator_ok=(count<2);
  *mac++ = val;
    }

    if (*str)
  return 0;

    return 1;
}

int wakeup(char * sMacAddr, char * sBroadcast, int iPort)
{
 WSADATA wsaData;
 int   s;
 struct sockaddr_in bcast;
 char msg[1024];
    int  msglen = 0;
 unsigned char macaddr[6];

 if (! parse_mac(macaddr, sMacAddr) )
 {
  cerr << "Illegal MAC address" << endl;
  return -1;
    }

 for (int i = 0; i < 6; i++) {
  msg[msglen++] = (char)0xff;
    }

    for (i = 0; i < 16; i++) {
  for (int j = 0; j < sizeof(macaddr); j++) {
   msg[msglen++] = macaddr[j];
  }
    }

 if (!WSAStartup(MAKEWORD(1, 1), &wsaData))
 {
  if ((s = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET)
  { 
   memset((char *)&bcast,0,sizeof(bcast));
   bcast.sin_family=AF_INET;
   bcast.sin_addr.s_addr=inet_addr(sBroadcast);
   bcast.sin_port=htons(iPort);

   if ( connect(s,(struct sockaddr *)&bcast,16)== -1)
   {
    cerr << "Cannot connect socket" << endl;
    return -2;
   }

   sendto(s, (const char *)&msg, msglen, 0, (struct sockaddr *)&bcast, sizeof(bcast));
   closesocket(s);
  }
  else
  {
   cerr << "Error getting socket" << endl;
  }

  WSACleanup();
  return(0);
 }
 else
  return -3;
}

void printHelp(char * argv[])
{
 cout << "WakeOnLan (c) erik.tornstam@home.se" << endl;
 cout << "Sends a WakeOnLan packet to a network." << endl << endl;
 cout << "Usage: " << argv[0] << " -a macaddress [-b broadcast address] [-p port] " << endl << endl;
 cout << "\t-a\tMAC-address of NIC to wake.  (00-04-00-c8-85-2d)" << endl;
 cout << "\t-b\tBroadcast address, default address is " << DEFAULT_BROADCAST << endl;
 cout << "\t-p\tPort number, default port is " << DEFAULT_PORT << endl;
}

int main(int argc, char* argv[])
{
 char macaddress[20] = "";
 char broadcast[20] = DEFAULT_BROADCAST;
 int port = DEFAULT_PORT;
 int argcnt=0;

 for(int c=1; c
 {
  if(stricmp("-a",argv[c])==0 && (argc > c+1) && argv[c+1][0]!='-')
  {
   strcpy(macaddress,argv[c+1]);
   argcnt++;
  }
  if(stricmp("-b",argv[c])==0 && (argc > c+1) && argv[c+1][0]!='-')
  {
   strcpy(broadcast,argv[c+1]);
   argcnt++;
  }
  if(stricmp("-p",argv[c])==0 && (argc > c+1) && argv[c+1][0]!='-')
  {
   port=atoi(argv[c+1]);
   argcnt++;
  }
 }

 if(argcnt < 1 || strcmp(macaddress,"")==0)
 {
  printHelp(argv);
  return -1;
 }
 cout << "Wakeupcall to " << macaddress << " broadcast over " << broadcast << " on port " << port << endl;
 wakeup(macaddress, broadcast, port);

 return 0;
}

출처 : http://visitagain.tistory.com/tag/WOL
VS2005 C++로 컴파일 해봤음, 오류남. ..

'Programming' 카테고리의 다른 글

11월 17일 랩실 C언어 교육  (0) 2009.11.17
WOL c++ 다른 소스코드  (0) 2009.10.29
IE8설치 후 VS에러 패치  (0) 2009.10.14
컴포넌트의 종류  (0) 2009.08.28
Flex Builder 3  (0) 2009.08.28
반응형

Magic Packet
I'm not sure, but it seems that the name comes from AMD. I did not do a search but Jos� Pedro Oliveira (second link above) says that there is more documentation about the protocol in their web site. As I mentioned above, you need to send a special packet in your LAN network, so that the remote computer will receive it and wake up. This so-called Magic packet consists of the following parts:

1.6 Bytes Header which is nothing but 6 bytes of 0xff.
2.16*6 Bytes Data. To produce data you'll need to repeat remote computers MAC (Media Access Control) Address 16 times. Look at the below figure:
 

Magic Packet(With Secure On Password)
(This part added on an update on: 2005/09/03. Note that 'PowerOn' sample has been updated in all downloads either. [as well as executables!])

Some clients require a password in the packet to be turned on, otherwise they simply won't! This password is also known as SecureOn, and will be attached at the end of the packet. In this case, a packet will look something like this:

 

So we have six cells, each capable of saving an integer number between 0 and 255(Just like MAC bytes).

'Network' 카테고리의 다른 글

전세계 공개 FTP 서버 리스트  (0) 2009.11.21
매직패킷 정리  (0) 2009.11.07
paros 3.2.13 - 웹 취약점 분석툴  (0) 2009.08.07
패킷 캡쳐 및 분석 - Wireshark  (0) 2009.07.09
proxy 유틸리티 - Burp Suit 1.2  (0) 2009.07.09
반응형

http://able.kbs.co.kr/live/index.html

에 가셔서 보고싶은 채널 선택하셔서 보시면 됩니다.

'Web' 카테고리의 다른 글

구글 애드센스 약관 및 정책  (0) 2009.12.17
웹분석 도구의 분류  (0) 2009.12.15
HTTP Debugger Pro v3.4 - 웹 분석 툴  (0) 2009.08.16
Google Dork part 1, 2  (0) 2009.08.07
Web 2.0  (0) 2009.08.07

+ Recent posts