[英]How to get IP Address from a FTP request in C#
我有一個傳入的 FTP 請求。 我想獲取傳入的 FTP 請求中提到的 FTP 服務器的 IP 地址。 我必須根據列入白名單的 FTP 服務器列表來驗證這一點。
任何幫助將不勝感激..
我的代碼如下:
try
{
IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(uri);
foreach (IPAddress ip in host.AddressList)
{
// we are only interested in IPV4 Addresses
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
}
}
return localIP;
}
catch (Exception exception)
{
throw;
}
好的,這是我的黑客..
private string GetFTPAddress(string uri)
{
try
{
// IPHostEntry host;
string localIP = null;
var entries = uri.Split('/');
var host = Dns.GetHostAddresses(entries[2]);
foreach (IPAddress ip in host)
{
// we are only interested in IPV4 Addresses
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
}
}
return localIP;
}
catch (Exception exception)
{
throw;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.