Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the code of LAN remote boot software

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to write the code of LAN remote boot software". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to write LAN remote boot software production code"!

The code is as follows:

/ *

> File Name: wake_up.c

> Author: wz

> Created Time: Fri 15 Nov 2013 03:42:47 PM CST

* * /

# include

# include

# include

# include

# include

# include

# include

Void get_mac (char * argv,unsigned char * save_mac)

{

Int j = 0

Int num_x = 0mm numb first = 1

While (* argv! = 0)

{

If (* argv! =':')

{

If (isdigit (* argv) & & first)

{

Num_x = (* argv -'0') * 16

First = 0

Argv++

Continue

}

If (first & & isalpha (* argv))

{

Num_x = (10 + (* argv -'a')) * 16

First = 0

Argv++

Continue

}

If (! first & & isdigit (* argv))

{

Num_x = num_x+ (* argv -'0')

First = 1

Argv++

Continue

}

If (! first & & isalpha (* argv))

{

Num_x = num_x + (10 + (* argv -'a'))

First = 1

Argv++

Continue

}

}

Else

{

Save_ Mac [j] = num_x

Num_x = 0

Argv++

Jacks +

}

}

Save_ Mac [j] = num_x

}

Int main (int argc,char * argv [])

{

Int sockfd,i,j,on = 1BI n

Unsigned char packet [120]

Unsigned char save_mac [120]

Struct sockaddr_in to

If (argc < 2)

{

Fprintf (stderr, "usage: program name + target host physical address")

Return 1

}

Get_mac (argv [1], save_mac)

/ / build magic packet

For (I = 0; I < 6; iTunes +)

{

Packet [I] = 0xff

}

For (I = 1; I < 17; iTunes +)

{

Memcpy (packet+i*6,save_mac,6)

}

Sockfd = socket (AF_INET,SOCK_DGRAM,0)

Setsockopt (sockfd,SOL_SOCKET,SO_BROADCAST,&on,sizeof (on))

If (socket < 0)

{

Fprintf (stderr, "socket creation error\ n")

Return 1

}

Memset ((void *) & to,0,sizeof (to))

To.sin_family = AF_INET

To.sin_port = htons (30000)

To.sin_addr.s_addr = inet_addr ("125.217.40.255")

N = sendto (sockfd,packet,sizeof (packet), 0, (struct sockaddr *) & to,sizeof (to))

If (n)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report