protected void Page_Load(object sender, EventArgs e) { LabelIp.Text = HttpContext.Current.Request.UserHostAddress; }
WebClient webClient = new WebClient(); string strExternalIp = webClient.DownloadString("http://checkip.dyndns.org/"); strExternalIp = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")).Matches(strExternalIp)[0].ToString();
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); // foreach (NetworkInterface nic in adapters) { string strInterfaceName = nic.Name; // string strPhysicalAddress = nic.GetPhysicalAddress().ToString(); // - string strAddr = string.Empty; // IP IPInterfaceProperties properties = nic.GetIPProperties(); foreach (UnicastIPAddressInformation unicast in properties.UnicastAddresses) { strAddr = unicast.Address.ToString() + " / " + unicast.IPv4Mask; } // - foreach (IPAddress dnsAddress in properties.DnsAddresses) { strAddr = dnsAddress.ToString(); } // foreach (GatewayIPAddressInformation gatewayIpAddressInformation in properties.GatewayAddresses) { strAddr = gatewayIpAddressInformation.Address.ToString(); } }
System.IO.File.WriteAllText("MyInterfaces.txt", strInterfaces);
MailMessage mail = new MailMessage { From = new MailAddress(strMailAddress), // Subject = strSubject, // Body = strBody, // IsBodyHtml = false }; mail.To.Add(new MailAddress(Settings.Default.strMailTo)); // SmtpClient client = new SmtpClient { Host = strSmtpServer, // SMTP Port = nSmtpServerPort, // SMTP EnableSsl = isSmtpSsl, // SSL Credentials = new NetworkCredential(strEmailUserName, strMailPassword), // DeliveryMethod = SmtpDeliveryMethod.Network }; client.Send(mail); // mail.Dispose();
// strFilePath - HttpWebRequest web = (HttpWebRequest)WebRequest.Create("https://webdav.yandex.ru/" + strFilePath); // (!!! ) web.Credentials = new NetworkCredential("mail@yandex.ru", "password"); web.Headers.Add("Authorization: Basic " + Convert.ToBase64String(Encoding.Unicode.GetBytes("mail@yandex.ru" + ":" + "password"))); web.Accept = "*/*"; web.Method = "PUT"; web.ContentType = "application/binary"; web.ContentLength = buffer.Length; using (Stream myReqStream = web.GetRequestStream()) { // strContent - byte[] buffer = Encoding.UTF8.GetBytes(strContent); myReqStream.Write(buffer, 0, buffer.Length); myReqStream.Flush(); } HttpWebResponse resp = (HttpWebResponse)web.GetResponse();
// var files = Directory.EnumerateFiles(" ", "*.txt"); strFileNames = files as string[] ?? files.ToArray(); foreach (string strFileName in strFileNames) { string message = File.ReadAllText(strFileName); // // - }
Imap4Client imap = new Imap4Client(); imap.ConnectSsl("imap.gmail.com", 993); // imap.Login("mail@google.com", "password");// Mailbox inbox = imap.SelectMailbox("inbox");// int[] nIdsUnread = inbox.Search("UNSEEN"); // int nUnreadCount = nIdsUnread.Length; // for (int i = 0; i < nUnreadCount; i++) { int idx = nIdsUnread[i]; // // Message message = inbox.Fetch.MessageObject(idx); // message.Subject - // message.BodyText.Text - // }
// strFilePath - HttpWebRequest web = (HttpWebRequest)WebRequest.Create("https://webdav.yandex.ru/" + strFilePath); // web.Credentials = new NetworkCredential("mail@yandex.ru", "password"); web.Headers.Add("Authorization: Basic " + Convert.ToBase64String(Encoding.Unicode.GetBytes("mail@yandex.ru" + ":" + "password"))); web.Accept = "*/*"; web.Method = "GET"; HttpWebResponse resp = (HttpWebResponse)web.GetResponse(); using (StreamReader sr = new StreamReader(resp.GetResponseStream())) { string text = sr.ReadToEnd(); // text - }
// strPath - HttpWebRequest web = (HttpWebRequest)WebRequest.Create("https://webdav.yandex.ru/" + strPath); // web.Credentials = new NetworkCredential("mail@yandex.ru", "password"); web.Headers.Add("Authorization: Basic " + Convert.ToBase64String(Encoding.Unicode.GetBytes("mail@yandex.ru" + ":" + "password"))); web.Accept = "*/*"; web.Headers.Add("Depth: 1"); web.Method = "PROPFIND"; List<string> retValue = new List<string>(); // HttpWebResponse resp = (HttpWebResponse)web.GetResponse(); using (StreamReader sr = new StreamReader(resp.GetResponseStream())) { // XML . : XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(sr.ReadToEnd()); XmlNodeList displaynames = xmlDoc.GetElementsByTagName("d:displayname"); int nCount = displaynames.Count; for (int i = 1; i < nCount; i++) { retValue.Add(displaynames[i].InnerText); } }
// string strHosts = File.ReadAllText(Environment.SystemDirectory + "\\drivers\\etc\\hosts"); string[] linesHostsOld = Regex.Split(strHosts, "\r\n|\r|\n"); // StringBuilder sbHostsNew = new StringBuilder(); // foreach (string lineHosts in linesHostsOld) { sbHostsNew.AppendLine(lineHosts); } // sbHostsNew.AppendLine("127.0.0.1 hello.world.com"); // File.WriteAllText(Environment.SystemDirectory + "\\drivers\\etc\\hosts", sbHostsNew.ToString());
DnsServer _server = new DnsServer(IPAddress.Any, 10, 10, ProcessQuery); _server.Start(); // // DNS private static DnsMessageBase ProcessQuery( DnsMessageBase message, IPAddress clientAddress, ProtocolType protocol) { message.IsQuery = false; DnsMessage query = message as DnsMessage; if (query != null) { if (query.Questions.Count == 1) { if (query.Questions[0].RecordType == RecordType.A) { if (query.Questions[0].Name.Equals("hello.world.com", StringComparison.InvariantCultureIgnoreCase)) { IPAddress ip; if (IPAddress.TryParse("127.0.0.1", out ip)) { query.ReturnCode = ReturnCode.NoError; DnsRecordBase rec = new ARecord(strHostName, 0, ip); query.AnswerRecords.Add(rec); return message; } } } } } message.ReturnCode = ReturnCode.ServerFailure; return message; }
Source: https://habr.com/ru/post/191172/
All Articles