예제 #1
0
 private void InitClient(ref TcpClient client, NetworkInterface Adapter)
 {
     Client = new TcpClient(new IPEndPoint(NetworkInstruments.getAdapterIPAddress(Adapter), 0));
     Client.ReceiveBufferSize = 10000;
     Client.SendBufferSize    = 10000;
     //Client.ReceiveTimeout = 500;
 }
예제 #2
0
 /// <summary>
 /// Инициализирует контроллер
 /// </summary>
 /// <param name="Adapter">Сетевой адаптер</param>
 /// <param name="al_port">Порт приложения</param>
 /// <param name="MasterPoint">Сетевая точка определяющая мастера, в случае режима мастера оставить null</param>
 public void InitInterface(NetworkInterface Adapter, int al_port, IPEndPoint MasterPoint)
 {
     if (state == ControllerState.Attacking)
     {
         Stop();
     }
     if ((al_port != CurrentPort) || (Adapter.Id != this.Adapter.Id) || ((MasterPoint != null) && (!MasterPoint.Equals(Master) || HostClient != null)) || ((MasterPoint == null) && (Master != null)))
     {
         Close();
         UpdateData("Customer initialization");
         try
         {
             CurrentPort  = al_port;
             MyPoint      = new IPEndPoint(NetworkInstruments.getAdapterIPAddress(Adapter), CurrentPort);
             this.Adapter = Adapter;
             if (MasterPoint == null)
             {
                 Master = null;
                 mode   = true;
                 InitServer();
                 //ChangeMode(true);
             }
             else
             {
                 Master = MasterPoint;
                 mode   = false;
                 ConnectToMaster();
             }
         }
         catch (SocketException err)
         {
             state = ControllerState.Error;
             if (err.SocketErrorCode == SocketError.AddressAlreadyInUse)
             {
                 UpdateData("Selected port is busy");
             }
             if (err.ErrorCode == (int)SocketError.AddressNotAvailable)
             {
                 UpdateData("No interface found for this address");
             }
         }
         catch (ObjectDisposedException) { return; }
     }
 }
예제 #3
0
 public void InitInterface(NetworkInterface Adapter, int al_port, IPEndPoint MasterPoint)
 {
     if (state == ControllerState.Attacking)
     {
         Stop();
     }
     if ((al_port != CurrentPort) || (Adapter.Id != this.Adapter.Id) || ((MasterPoint != null) && (!MasterPoint.Equals(Master))) || ((MasterPoint == null) && (Master != null)))
     {
         Close();
         UpdateData("Инициализация клиентов");
         try
         {
             CurrentPort  = al_port;
             MyPoint      = new IPEndPoint(NetworkInstruments.getAdapterIPAddress(Adapter), CurrentPort);
             this.Adapter = Adapter;
             if (MasterPoint == null)
             {
                 mode = true;
                 InitServer();
                 //ChangeMode(true);
             }
             else
             {
                 Master = MasterPoint;
                 mode   = false;
                 ConnectToMaster();
             }
         }
         catch (SocketException err)
         {
             state = ControllerState.Error;
             if (err.SocketErrorCode == SocketError.AddressAlreadyInUse)
             {
                 UpdateData("Выбранный порт занят");
             }
             if (err.ErrorCode == (int)SocketError.AddressNotAvailable)
             {
                 UpdateData("Не найдено интерфейса с таким адресом");
             }
         }
         catch (ObjectDisposedException) { return; }
     }
 }
예제 #4
0
 private void fillAdapterList()
 {
     NetworkInterface[] AdaptersRange = NetworkInterface.GetAllNetworkInterfaces();
     Adapters = new List <NetworkInterface>();
     for (int i = 0; i < AdaptersRange.Length; ++i)
     {
         if (AdaptersRange[i].OperationalStatus == OperationalStatus.Up && AdaptersRange[i].NetworkInterfaceType != NetworkInterfaceType.Loopback && NetworkInstruments.getAdapterIPAddress(AdaptersRange[i]) != IPAddress.Any)
         {
             Adapters.Add(AdaptersRange[i]);
             AdapterBox.Items.Add(AdaptersRange[i].Name + " Status: " + AdaptersRange[i].OperationalStatus.ToString() + " Type: " + AdaptersRange[i].NetworkInterfaceType);
             if (AdaptersRange[i].Id == curAdapter.Id)
             {
                 AdapterBox.SelectedIndex = AdapterBox.Items.Count - 1;
             }
         }
     }
     if (AdapterBox.SelectedIndex == -1 && AdapterBox.Items.Count != 0)
     {
         AdapterBox.SelectedIndex = 0;
     }
 }
예제 #5
0
 private void AdapterBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     IpLab.Text  = NetworkInstruments.getAdapterIPAddress(Adapters[AdapterBox.SelectedIndex]).ToString();
     MacLab.Text = Adapters[AdapterBox.SelectedIndex].GetPhysicalAddress().ToString();
 }