Linux 遠端啟動計算機

2021-10-06 03:30:49 字數 4793 閱讀 1146

1、檢視主控機是否支援

#ethtool eth0

settings for eth0:

supported ports: [ tp mii ]

supported link modes: 10baset/half 10baset/full

100baset/half 100baset/full

1000baset/full

supported pause frame use: symmetric receive-only

supports auto-negotiation: yes

supported fec modes: not reported

advertised link modes: 10baset/half 10baset/full

100baset/half 100baset/full

1000baset/full

advertised pause frame use: symmetric

advertised auto-negotiation: yes

advertised fec modes: not reported

link partner advertised link modes: 10baset/half 10baset/full

100baset/half 100baset/full

1000baset/full

link partner advertised pause frame use: symmetric

link partner advertised auto-negotiation: yes

link partner advertised fec modes: not reported

speed: 1000mb/s

duplex: full

port: mii

phyad: 1

transceiver: internal

auto-negotiation: on

supports wake-on: pumbag

wake-on: d

current message level: 0x00000007 (7)

drv probe link

link detected: yes

2、看到wake-on: d,表示沒有開啟wake控制,需要開啟為wake-on:g

#ethtool -s eth0 wol g

#ethtool eth0

settings for eth0:

supported ports: [ tp mii ]

supported link modes: 10baset/half 10baset/full

100baset/half 100baset/full

1000baset/full

supported pause frame use: symmetric receive-only

supports auto-negotiation: yes

supported fec modes: not reported

advertised link modes: 10baset/half 10baset/full

100baset/half 100baset/full

1000baset/full

advertised pause frame use: symmetric

advertised auto-negotiation: yes

advertised fec modes: not reported

link partner advertised link modes: 10baset/half 10baset/full

100baset/half 100baset/full

1000baset/full

link partner advertised pause frame use: symmetric

link partner advertised auto-negotiation: yes

link partner advertised fec modes: not reported

speed: 1000mb/s

duplex: full

port: mii

phyad: 1

transceiver: internal

auto-negotiation: on

supports wake-on: pumbag

wake-on: g

current message level: 0x00000007 (7)

drv probe link

link detected: yes

這樣就開啟wake控制了。

3、python 程式設計

#!/usr/bin/python

# -*- coding: utf-8 -*-

import socket

import binascii

import struct

import re

'''格式化mac位址,生成魔法喚醒包,然後傳送。

mac格式: mac = a1b2c3d4e5f6

喚醒包格式: send_data = binascii.unhexlify('ff'*6 + str(mac)*16)

'''mac = "94:c6:91:72:d8:00"

# mac = "98-90-96-c1-fe-cb"

# 格式化mac位址989096c1fecb為這種形式

def format_mac0(mac):

if len(mac) == 12:

pass

elif len(mac) == 17:

if mac.count(':') == 5 or mac.count('-') == 5:

sep = mac[2]

mac = mac.replace(sep, '')

else:

raise valueerror('incorrect mac format')

else:

raise valueerror('incorrect mac format')

return mac

def format_mac(mac):

mac_re = re.compile(r'''

(^([0-9a-f][-])([0-9a-f])$

|^([0-9a-f][:])([0-9a-f])$

|^([0-9a-f][.])([0-9a-f])$

)''', re.verbose | re.ignorecase)

# print(re.match(mac_re, mac))

if re.match(mac_re, mac):

if mac.count(':') == 5 or mac.count('-') == 5 or mac.count('.'):

sep = mac[2]

mac_fm = mac.replace(sep, '')

return mac_fm

else:

raise valueerror('incorrect mac format')

def create_magic_packet0(mac):

data = b'ff' * 6 + (mac * 16).encode()

print(data)

print(type(data))

send_data = b''

for i in range(0, len(data), 2):

send_data = send_data + struct.pack(b'b', int(data[i: i + 2], 16)) # int(data[i: i+2], 16) 把16進製制轉換成整數

print(type(send_data))

return send_data

def create_magic_packet(mac):

data = 'ff' * 6 + str(mac) * 16

# print(data)

# print(type(data))

send_data = binascii.unhexlify(data)

# print(type(send_data))

return send_data

def send_magic_packet(send_data):

# broadcast_address = '192.168.255.255'

broadcast_address = '255.255.255.255'

port = 9

s = socket.socket(socket.af_inet, socket.sock_dgram)

s.setsockopt(socket.sol_socket, socket.so_broadcast, 1)

s.sendto(send_data, (broadcast_address, port))

if __name__ == '__main__':

mac = format_mac(mac)

send_data = create_magic_packet(mac)

# print(send_data)

send_magic_packet(send_data)

執行python wake_on_lan.py

開機成功。

計算機遠端操作

一,ping 它是用來檢查網路是否通暢或者網路連線速度的命令。作為乙個生活在網路上的管理員或者黑客來說,ping命令是第乙個必須掌握的dos命令,它所利用的原理是這樣的 網路上的機器都有唯一確定的ip位址,我們給目標ip位址傳送乙個資料報,對方就要返回乙個同樣大小的資料報,根據返回的資料報我們可以確...

計算機啟動流程

系統啟動流程 我們幾乎每天都要開啟電源啟動機器,面對螢幕上出現的一幅幅啟動畫面,我們一點兒也不會感到陌生,但是,計算機在顯示這些啟動畫面時都做了些什麼工作呢?開啟計算機機電源後到計算機準備接受你發出的命令之間計算機所執行的過程稱為引導 boot 過程。我們知道,當關閉電源後,ram的資料將丟失,因此...

計算機啟動分析

計算機的啟動一般分為四個階段 bios程式為開機自檢程式,是固化在rom晶元中。正如其英文表達意思,basic input output system 基本輸入輸出系統 當控制權轉移到優先順序第一的儲存裝置上後,計算機會讀取該裝置的第乙個扇區,即最前面512個位元組。觀察512個位元組中最後2個位元...