public WebServer(int port, Log log, CaptureView captureView,Option option) { _log = log; _port = port; _runMode = option.RunMode; _captureView = captureView; _documentRoot = Path.GetFullPath(Directory.GetCurrentDirectory() + "\\..\\..\\..\\www"); _log.Clear(); log.Set(string.Format("Mode={0}",_runMode)); _t = new Thread(Loop) { IsBackground = true }; if (_runMode != RunMode.Pcap) { _captureView.Enable= false; } else { _capture = new Capture(); _substitute = new Substitute(_capture, _port,option.AckReply,option.ArpReplyList, _log); _capture.OnCapture += new OnCaptureHandler(_capture_OnCapture); _captureView.Enable = true; var ar = _capture.GetAdapterList(); _captureView.Adapter = null; int index = option.AdapterIndex; bool promiscuous = false; _capture.Start(ar[index].Name, promiscuous); _captureView.Adapter = ar[index]; _substitute.Adapter = ar[index]; } _t.Start(); }
public Substitute(Capture capture,int port,bool arpReply,List<string> arpReplyList,Log log) { _port = port; _arpReplay = arpReply; _arpReplyList = arpReplyList; _log = log; capture.OnCapture += new OnCaptureHandler(capture_OnCapture); }
public OptionDlg(Option option) { InitializeComponent(); Option = option; radioButtonNone.Checked = (option.RunMode == RunMode.None); radioButtonBind.Checked = (option.RunMode == RunMode.Bind); radioButtonPcap.Checked = (option.RunMode == RunMode.Pcap); checkBoxAckReply.Checked = option.AckReply; var sb = new StringBuilder(); foreach(var ip in option.ArpReplyList){ sb.Append(ip); sb.Append("\n"); } textBox1.Text = sb.ToString(); Capture capture = new Capture(); var ar = capture.GetAdapterList(); foreach (var a in ar) { sb = new StringBuilder(); sb.Append(a.Description); sb.Append(" "); foreach (var s in a.Ip) { sb.Append(s); sb.Append(" , "); } listBoxAdapter.Items.Add(sb.ToString()); } if (listBoxAdapter.Items.Count > 0) { listBoxAdapter.SelectedIndex = 0; if (listBoxAdapter.Items.Count > option.AdapterIndex) listBoxAdapter.SelectedIndex = option.AdapterIndex; } else { //アダプタが列挙できていないときは、Pcapモードは使用できない radioButtonPcap.Enabled = false; } initDisplay(); }
public void Dispose() { if (_t != null) {//起動されている場合 _life = false;//スイッチを切るとLoop内の無限ループからbreakする if (_t.IsAlive) { Thread.Sleep(100); } } _t = null; if (_runMode == RunMode.Pcap) { _capture.OnCapture -= _capture_OnCapture; _capture.Dispose(); _capture = null; _substitute = null; } }