rendered paste bodyusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
namespace IP_Viewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public String strHostname = "";
private void Form1_Load(object sender, EventArgs e)
{
GetLocalHostname();
GetLocalIP();
GetExtIP();
GetExtHostname();
}
private void GetLocalHostname()
{
strHostname = Dns.GetHostName();
HostnameTextBox.Text = strHostname;
}
private void GetLocalIP()
{
IPHostEntry ipEntry = Dns.GetHostEntry(strHostname);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
IPTextBox.Text += addr[i].ToString();
}
}
public void GetExtIP()
{
string myWanIp = "http://www.mywanip.com";
string strToFind = "\"ipaddress\">";
string requestLine = "";
HttpWebResponse response = null;
HttpWebRequest request;
try
{
request = (HttpWebRequest)WebRequest.Create(myWanIp);
response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), true);
while (!reader.EndOfStream)
{
requestLine = reader.ReadLine();
if (requestLine.Contains(strToFind))
{
requestLine = requestLine.Replace("<p class=\"ipaddress\">", "");
requestLine = requestLine.Replace("</p>", "");
ExtIPTextBox.Text = requestLine;
}
}
}
catch (WebException ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void GetExtHostname()
{
try
{
IPHostEntry IpEntry = Dns.GetHostByAddress(ExtIPTextBox.Text);
ExtHostnameTextBox.Text = IpEntry.HostName.ToString();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void RefreshButton_Click(object sender, EventArgs e)
{
HostnameTextBox.Clear();
IPTextBox.Clear();
ExtHostnameTextBox.Clear();
ExtIPTextBox.Clear();
GetLocalHostname();
GetLocalIP();
GetExtIP();
GetExtHostname();
}
private void Form1_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
}
private void RestoreItem_Click(object sender, EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
}
private void CloseItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}