Welcome to the Coding Planet!
HomeHome  ­PortalPortal  ­RegisterRegister  ­Log inLog in  
Share | 
 

 IP Viewer C#.NET

View previous topic View next topic Go down 
AuthorMessage
Brolly
Admin
Admin


Posts: 3
Join date: 2008-04-24

PostSubject: IP Viewer C#.NET   Tue May 06, 2008 10:08 pm

http://rapidshare.com/files/94817897/IP_Viewer.exe.html


Code:
using 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.IO;

namespace IP_Viewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private 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;
            HttpWebRequest request;
           
            try
            {
                request = (HttpWebRequest)WebRequest.Create(myWanIp);             
                request.Method = "GET";
                response = (HttpWebResponse)request.GetResponse();

                StreamReader reader = new StreamReader(response.GetResponseStream());

                while (!reader.EndOfStream)
                {
                    requestLine = reader.ReadLine();
                    if (requestLine.Contains(strToFind))
                    {
                        requestLine = requestLine.Replace("<p class=\"ipaddress\">", "");
                        requestLine = requestLine.Replace("</p>", "");
                        ExtIPTextBox.Text = requestLine;
                        break;
                    }
                }
                request.Abort();
                reader.Close();
                response.Close();
            } 
            catch (WebException ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                ExtIPTextBox.Text = "Error";
            }
           
        }

        private void GetExtHostname()
        {
            try
            {
                IPHostEntry IpEntry = Dns.GetHostByAddress(ExtIPTextBox.Text);
                ExtHostnameTextBox.Text = IpEntry.HostName.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                ExtHostnameTextBox.Text = "Error";
            }
        }

        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();
        }

    }
}
Back to top Go down
View user profile
r1Nu-
Admin
Admin


Posts: 13
Join date: 2008-04-24
Age: 19
Location: 192.178.**.**

PostSubject: Re: IP Viewer C#.NET   Tue May 06, 2008 10:11 pm

Nice Brolly..to eixa dei kai paliotera otan to ekanes..arketa xrisimo programmataki...
..g00d j0b br0! Smile

r1Nu-
Back to top Go down
View user profile http://code-masters.darkbb.com
 

IP Viewer C#.NET

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
Code-Masters :: Coding :: C#-