多网卡指定网卡发送数据包 C# 实现代码

来源:互联网 发布:家电遥控器软件 编辑:程序博客网 时间:2024/06/06 03:05
  1. 转自:http://blog.csdn.net/ssihc0/article/details/5861358
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Text;  
  5. using System.Net.Sockets;  
  6. using System.Net;  
  7.   
  8. namespace udpTest  
  9. {  
  10.     class Program  
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.             //网卡1  
  15.             IPEndPoint ipe= new IPEndPoint(IPAddress.Parse("192.168.1.65"),5212);  
  16.             //网卡2  
  17.             IPEndPoint ipe1 = new IPEndPoint(IPAddress.Parse("192.168.1.67"), 5213);  
  18.   
  19.             //目标服务器  
  20.               IPEndPoint ipe2= new IPEndPoint(IPAddress.Parse("192.168.1.17"),5000);  
  21.   
  22.             //用网卡1发  
  23.                 UdpClient udp = new UdpClient(ipe); 
  24.  
  25.                 
  26. string s = "b0487a1a34";
  27.             
  28.                        
  29.             byte[] by = Encoding.UTF8.GetBytes(s);
  •                 udp.Send(by, by.Length,ipe2);  
  •   
  •                 //用网卡2发  
  •   
  •                 UdpClient udp1 = new UdpClient(ipe1);  
  •                 udp1.Send(by, by.Length, ipe2);      
  •         
  •              
  •         }  
  •     }  
  • }  
  • 0 0
    原创粉丝点击