TCPconnection by Powershell
TCP by Powershell
手順
- new tcpclient
- stream to reader
- check .Connected
- read(buffer,0,size)
- 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
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-"
開放が必要なポート
UAC
User Access Controlに拒否される場合がある。その場合は、UAC無効化が必要。
レジストリ
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://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
http://takuya-1st.hatenablog.jp/entry/2014/08/03/170845
以上
WPF複数ページ
WPF複数ページ
題名通り、WPFでの複数ページ対応方法。
- 子ウインドウ
- NavigationWindow
- TabControl
用途に応じて使い分ける。
初心者向けの初期設定などの一方通行型としたい場合は、NavigationWindow。バックも可能だが、一本道だとユーザーが次に何をするか悩みにくい。
ダッシュボードの様に、常に決まった初期ウインドウ上で作業し続ける事が多い場合は、子ウインドウ。モーダル、非モーダルを選べる。常にメインウインドウが存在し、安心感がある。
継続利用し、かつ、使用者が熟練する事を想定し、高い柔軟性を盛り込みたい場合はTabControl。但し、乱用すると最初にどのタブを使う必要があるのか、どのタブに欲しい機能があるのかなど、使用者が迷う可能性があり、初心者向けではないかもしれない。特に階層を深くすればするほど、迷子を量産するので、注意が必要である。とは言え、10タブx3階層とすれば、1000ページを収納でき、他に比べ圧倒的な収容力を誇る。
非同期実行 by powershell
非同期実行 by powershell
- RunSpace
- Start-Job
- Start-Process
- AppDomain
- 独立アプリ起動
- System.Diagnostics.Process
非同期中、標準入出力を制御できるもの。
- Start-Job : receive-job
- Start-Process: ファイル指定
- Process: Stream
終了値を取得できるもの
- RunSpace
- Start-Process
- Process
面倒ではあるが、Start-Processか、Processクラスを使用するのが最も柔軟性が高い。
簡単さを追い求めるなら、Start-jobが楽ではあるが、それでもRemove-Jobなどの後処理が必要。
最初は面倒ではあるが、ライブラリを作ってProcessクラスを使用するのも一つの手。
但し、今の所、非同期プロセスの標準出力を受け取り、WPFの様な別スレッドで使う方法が確立できておらず、もう少し調査が必要。
ProcessのDataReceivedEvent からのWPF/UIスレッドのDispatcher.BeginInvoke(Action)をPowerShellで試行した限りでは、Delegate=Actionの型が合わずにエラーとなり、未だ成功していない。手持ちの対策候補はスクリプトブロックを[action]型にキャストする程度であり、時間ができたら試行する予定。
SSH by Powershell
ssh by powershell
ssh.net + PowerShell
opensshも出ているが、PowerShellで使うにはモジュールの方が便利かもしれない。
参考
http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library