Đoạn mã lấy IP của 1 máy trong mạng Lan, hay IP của 1 trang web.
[csharp]
string host = "www.sqlvn.com";
try
{
IPAddress[] addresses = Dns.GetHostAddresses(host);
foreach (IPAddress addr in addresses)
{
Console.Write(addr+Environment.NewLine);
}
Console.ReadLine();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
[/csharp]
Kết quả khi chạy chương trình:

-------------------------------------------------------------------------------------------
Đoạn mã lấy HTML nội dung của 1 trang web:
WebClient webClient = new
WebClient();
Stream objStream;
StreamReader objStreamReader;
string htmlResult = "";
bool requestStatus = false;
StringBuilder sbEmailList = new
StringBuilder();
string domainName = "tenmienthuonghieu.com";
try
{
objStream = webClient.OpenRead("http://" + domainName);
objStreamReader = new
StreamReader(objStream);
htmlResult = objStreamReader.ReadToEnd();
requestStatus =
true;
Console.WriteLine(htmlResult);
}
catch
{
requestStatus = false;
}
Console.ReadLine();
Quang Vinh
mai.quangvinh@sqlvn.com
0 comments:
Post a Comment