2018年2月19日月曜日

VinoでVNC

XubuntuでVNCサーバを設定するノート

VNCサーバ

vinoをインストールする.
#vino-preferences
で設定起動.
以下のチェックを入れる.
[Sharing]
Allow other users to view your desktop
 Allow other users to control your desktop

以下のチェックを外す.
[Security]
You must confirm each access to this machine

暗号化を使わない場合,
#gsettings set org.gnome.Vino require-encryption false
とする.
サーバーの場所は以下,
#/usr/lib/vino/vino-server
スタートアップに設定しておくと楽.
VNCクライアントからは, IPアドレス:ディスプレイ番号で接続する. ディスプレイ番号が0なら省略可能.

Wake On LAN

まず, BIOS設定からそれっぽいものを有効にする.
ethtoolをインストールして, ツールにインターフェイス名を指定して情報を表示する.
以下のように, ステータスがdになっていれば無効になっている.
#apt install ethtool
#ethtool enp1s0
    ----
    Wake-on: d
    ----
以下のように有効化, 必要なら適当な箇所で有効になるように設定する.
ステータスがgになっていれば有効.
#ethtool -s enp1s0 wol g
    ----
    Wake-on: g
    ----

.Netから叩き起こす
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace WakeOnLAN
{
    class Program
    {
        static void Main(string[] args)
        {
            if(args.Length<2) {
                System.Console.WriteLine("Usage: <global ip address> <mac address>");
                return;
            }
            try {
                IPAddress globalAddress = null;
                if(!IPAddress.TryParse(args[0], out globalAddress)) {
                    return;
                }
                PhysicalAddress physicalAddress = PhysicalAddress.Parse(args[1]);
                using(MemoryStream memoryStream = new MemoryStream())
                using(BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                using(UdpClient client = new UdpClient()) {
                    for(int i = 0; i<6; ++i) {
                        binaryWriter.Write((byte)0xFF);
                    }
                    byte[] bytes = physicalAddress.GetAddressBytes();
                    for(int i = 0; i<16; ++i) {
                        binaryWriter.Write(bytes);
                    }

                    binaryWriter.Flush();
                    byte[] sendData = memoryStream.ToArray();
                    client.EnableBroadcast = true;
                    client.Send(sendData, sendData.Length, new IPEndPoint(globalAddress, 0));
                    client.Close();
                }

            } catch {
                return;
            }
        }
    }
}

0 件のコメント:

コメントを投稿