在C#中的控制台/Windows应用程序中检测IP地址 [英] Detect IP address in console/windows application in c#
问题描述
如何编写我自己的防火墙来检测渗透器ip.它不是Web应用程序.
如何制作Wireshark或Ethereal之类的应用程序
如何在C#中的控制台/Windows应用程序中检测IP地址?
在Web站点中执行此操作很容易,但我无法在Console/Windows应用程序中了解如何检测传入数据包/请求的IP.
如果它在控制台/Windows应用程序中的机器上保存了一些文件,如何获取未知机器的ip
How to write my own firewall to detect the infiltrator ip . It is not a web application .
How to make application like Wireshark or Ethereal
How to Detect IP address in console/windows application in c# ?
Doing it in Web site is easy but i am not getting how to detect the ip of incoming packet / request in the Console/ windows application.
How to get the ip of an unknown machine if it is saving some file on my machine in a console / Windows application
推荐答案
尝试以下代码:
使用System.Net;
Try this code:
using System.Net;
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
foreach(IPAddress address in localIPs)
MessageBox.Show(address.ToString());
1.1框架:
1.1 Framework:
StringBuilder sb = new StringBuilder();
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
sb.Append(addr[i].ToString());
}
string myip = sb.ToString();
2.0或更高版本的框架
2.0 or later framework
StringBuilder sb = new StringBuilder();
// Get the hostname
string myHost = System.Net.Dns.GetHostName();
System.Net.IPHostEntry myIPs = System.Net.Dns.GetHostEntry(myHost);
foreach(System.Net.IPAddress myIP in myIPs.AddressList)
sb.Append(myIP.ToString());
string myip = sb.ToString();
亲爱的
试试下面的代码
hi dear
try below code
public void getLocalIPAddress()
{
try
{
string sHostName = Dns.GetHostName();
IPHostEntry ipE = Dns.GetHostByName(sHostName);
IPAddress[] IpA = ipE.AddressList;
for (int i = 0; i < IpA.Length; i++)
{
Console.WriteLine("IP Address {0}: {1} ", i, IpA[i].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "getLocalIPAddress");
}
}
这篇关于在C#中的控制台/Windows应用程序中检测IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!