我有一个传入的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;
}
答案 0 :(得分:5)
好的,这是我的黑客..
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;
}
}