class GetIP { public static void Main() { Console.WriteLine (Host name : {0}, Dns.GetHostName()); } } 二十、发送邮件: using System; using System.Web; using System.Web.Mail; public class TestSendMail { public static void Main() { try { // Construct a new mail message MailMessage message = new MailMessage(); message.From = from@domain.com; message.To = pengyun@cobainsoft.com; message.Cc = ; message.Bcc = ; message.Subject = Subject; message.Body = Content of message; //if you want attach file with this mail, add the line below message.Attachments.Add(new MailAttachment(c:\\attach.txt, MailEncoding.Base64)); // Send the message SmtpMail.Send(message); System.Console.WriteLine(Message has been sent); } catch(Exception ex) { System.Console.WriteLine(ex.Message.ToString()); } } } 二十一、根据IP地址得出机器名称: using System; using System.Net; class ResolveIP { public static void Main() { IPHostEntry ipEntry = Dns.Resolve(172.29.9.9); Console.WriteLine (Host name : {0}, ipEntry.HostName); } } |