qshinoの日記

Powershell関係と徒然なこと

下田

とりあえず、休みなので下田で一泊。

車で約4時間かかり、結構疲労もあったので、宿近くの居酒屋で地魚丼なるものを食べる。思いの外美味しく、流石海が近いだけの事はある。

とは言え、街まで行く気力もなく早々に宿に戻り温泉に入って寝る。だがしかし、久しぶりに遠出したためか、全く寝られず、完徹。体を横に出来ただけで、これからが厳しくなる見込み。

博物館、了仙寺、ロープウェイや灯台など、行きたい所は多々あるものの、何処まで行ける事やら。

TCPconnection by Powershell

TCP by Powershell

手順

  1. new tcpclient
  2. stream to reader
  3. check .Connected
  4. read(buffer,0,size)
  5. Write
$tcpConnection = New-Object System.Net.Sockets.TcpClient($FTPServer, $FTPPort)
$tcpStream = $tcpConnection.GetStream()
$reader = New-Object System.IO.StreamReader($tcpStream)
$writer = New-Object System.IO.StreamWriter($tcpStream)
$writer.AutoFlush = $true

$buffer = new-object System.Byte[] 1024
$encoding = new-object System.Text.AsciiEncoding 

while ($tcpConnection.Connected)
{
    while ($tcpStream.DataAvailable)
    {

        $rawresponse = $reader.Read($buffer, 0, 1024)
        $response = $encoding.GetString($buffer, 0, $rawresponse)   
    }

    if ($tcpConnection.Connected){
        Write-Host -NoNewline "prompt> "
        $command = Read-Host

        if ($command -eq "escape"){
            break
        }

        $writer.WriteLine($command) > $null
    }
    start-sleep -Milliseconds 500
}

$reader.Close()
$writer.Close()
$tcpConnection.Close()

MTU/MSS

パケッサイズ

MTU/MSS

MTU: Maximum Transmission Unit

MSS: Maximum Segment Size

  • Max. Ethernet Frame Size: 1518
  • IP MTU : 1500
  • MSS :

Header/Trailer Size List

  • Ethernet: 14 +4 = 18
  • PPPoE header : 6
  • PPP : 2
  • IP : 20
  • TCP: 20
  • UDP : 8
  • IPsec esp tunnel mode: 36-65
  • L2TPv3 over ip : 8
  • L2TPv3 over udp:
  • EtherIP :

IPsec header

Tunnel mode

IPヘッダ: 20バイト
SPI: 4バイト
シーケンス番号: 4バイト
初期ベクトル: 8、または16バイト (DES-CBC、3DES-CBCでは8バイト、AES-CBCでは16バイト)
パディング: 0~7バイト (パケットの全長が8の倍数になるように付与する)
パディングの長さ: 1バイト
プロトコル: 1バイト
認証データ: 0、または12バイト (認証の設定がなければ0バイト、あれば12バイト)

Tunnel sample

IPヘッダ: 20バイト
SPI: 4バイト
シーケンス番号: 4バイト
初期ベクトル: 8バイト
パディング: 4バイト
パディングの長さ: 1バイト
プロトコル: 1バイト
認証データ: 12バイト

Ethernet Format

IP format

TCP format

[ether14][IP 20][TCP 20][Payload][ether fcs 4]

UDP format

[ether14][IP 20][UDP 8][Payload][ether fcs 4]

IPsec transport

[ether14][IP 20][esp ][TCP 20][Payload][ether fcs 4]

IPsec tunnel

[ether14][IP 20][esp ][IP 20][TCP 20][Payload][ether fcs 4]

L2TPv3 over ip

[ether14][IP 20][l2tp 8 ][ether14][IP 20][TCP 20][Payload][ether fcs 4][ether fcs 4]

l2tpv3 over ipsec transport

[ether14][IP 20][esp][l2tp 8 ][ether14][IP 20][TCP 20][Payload][ether fcs 4]/[ether fcs 4]

参考

ether/ip/tcp/ppp/pppoe

http://www.infraexpert.com/info/5adsl.htm

ipsec

http://www.rtpro.yamaha.co.jp/RT/FAQ/IPsec/faq_2_l.html

L2TPv3

http://www.rtpro.yamaha.co.jp/RT/docs/l2tpv3/

http://www.rtpro.yamaha.co.jp/RT/docs/l2tpv3/

https://tools.ietf.org/html/rfc3931

etherip

LinuxからWindows制御

LinuxからWindows制御

winexeが使える。

コンピュータ名 hunnyの場合。

winexe -U hunny/Administrator%poi //192.168.1.1 "echo Oha-"

開放が必要なポート

  • 135/tcp(RPCエンドポイント・マッパー)
  • 445/tcp(ダイレクト・ホスティングSMB)
  • 1025~65535/tcp(RPC動的ポート)

UAC

User Access Controlに拒否される場合がある。その場合は、UAC無効化が必要。

レジストリ

win7ではレジストリ変更が必要。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

のDWordで

LocalAccountTokenFilterPolicy = 1

エラーの場合

下記のエラーが出る場合

[winexe/winexe.c:120:on_ctrl_pipe_error()] ERROR: Failed to install service winexesvc – NT code 0x00000424

サービス登録する

sc create winexesvc binPath= C:\WINDOWS\WINEXESVC.EXE start= auto DisplayName= winexesvc
sc description winexesvc “Remote command provider for Zenoss monitoring”

https://orebibou.com/2015/03/linuxでコンソールからwindowsを操作しよう!psexecのlinux版『winexe』/

参考

winexe

http://eol.ovh.org/winexe/

http://technet.microsoft.com/ja-jp/magazine/cc162490.aspx

http://www.atmarkit.co.jp/fsecurity/column/ueno/43.html

https://www.google.co.jp/amp/fujishinko.exblog.jp/amp/8239119/

UAC無効化

http://www.atmarkit.co.jp/ait/spv/0703/09/news127.html

Win7ではレジストリ変更が必要。

http://takuya-1st.hatenablog.jp/entry/2014/08/03/170845

以上

WPF複数ページ

WPF複数ページ

題名通り、WPFでの複数ページ対応方法。

  1. 子ウインドウ
  2. NavigationWindow
  3. TabControl

用途に応じて使い分ける。

  1. 初心者向けの初期設定などの一方通行型としたい場合は、NavigationWindow。バックも可能だが、一本道だとユーザーが次に何をするか悩みにくい。

  2. ダッシュボードの様に、常に決まった初期ウインドウ上で作業し続ける事が多い場合は、子ウインドウ。モーダル、非モーダルを選べる。常にメインウインドウが存在し、安心感がある。

  3. 継続利用し、かつ、使用者が熟練する事を想定し、高い柔軟性を盛り込みたい場合はTabControl。但し、乱用すると最初にどのタブを使う必要があるのか、どのタブに欲しい機能があるのかなど、使用者が迷う可能性があり、初心者向けではないかもしれない。特に階層を深くすればするほど、迷子を量産するので、注意が必要である。とは言え、10タブx3階層とすれば、1000ページを収納でき、他に比べ圧倒的な収容力を誇る。