Underc0de - La Casa de los Informáticos

Programación General => C# - VB.NET => Mensaje iniciado por: BigBear en Julio 04, 2014, 02:24:46 PM

Título: [C#] LocateIP 0.2
Publicado por: BigBear en Julio 04, 2014, 02:24:46 PM
Un simple programa en C# para localizar una IP , su localizacion y sus DNS.

Una imagen :

(http://doddyhackman.webcindario.com/images/locateipcsharp.jpg)

El codigo :

Form1.cs

Código (csharp) [Seleccionar]

// LocateIP 0.2
// (C) Doddy Hackman 2014
// Credits :
// To locate IP : http://www.melissadata.com/lookups/iplocation.asp?ipaddress=
// To get DNS : http://www.ip-adress.com/reverse_ip/
// Theme Skin designed by Aeonhack
// Thanks to www.melissadata.com and www.ip-adress.com and Aeonhack

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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

        }

        private void mButton2_Click(object sender, EventArgs e)
        {           
            funciones modulos = new funciones();

            if (textBox1.Text == "")
            {
                MessageBox.Show("Enter the target");
            }
            else
            {

                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
                listBox1.Items.Clear();

                toolStripStatusLabel1.Text = "[+] Getting IP ...";
                this.Refresh();


                string ip = modulos.getip(textBox1.Text);
                if (ip == "Error")
                {
                    MessageBox.Show("Error getting IP ...");
                    toolStripStatusLabel1.Text = "[-] Error getting IP";
                    this.Refresh();
                }
                else
                {
                    textBox1.Text = ip;
                    toolStripStatusLabel1.Text = "[+] Locating ...";
                    this.Refresh();
                    List<String> localizacion = modulos.locateip(ip);
                    if (localizacion[0] == "Error")
                    {
                        MessageBox.Show("Error locating ...");
                        toolStripStatusLabel1.Text = "[-] Error locating";
                        this.Refresh();
                    }
                    else
                    {
                        textBox2.Text = localizacion[0];
                        textBox3.Text = localizacion[1];
                        textBox4.Text = localizacion[2];

                        toolStripStatusLabel1.Text = "[+] Getting DNS ...";
                        this.Refresh();

                        List<String> dns_found = modulos.getdns(ip);
                        if (dns_found[0] == "")
                        {
                            MessageBox.Show("Error getting DNS ...");
                            toolStripStatusLabel1.Text = "[-] Error getting DNS";
                            this.Refresh();
                        }
                        else
                        {

                            foreach (string dns in dns_found)
                            {
                                listBox1.Items.Add(dns);
                            }

                            toolStripStatusLabel1.Text = "[+] Finished";
                            this.Refresh();
                        }

                    }

               
                }

            }
           
        }

        private void mButton1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

// The End ?


funciones.cs

Código (csharp) [Seleccionar]

// Funciones for LocateIP 0.2
// (C) Doddy Hackman 2014

using System;
using System.Collections.Generic;
using System.Text;

//
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
//

namespace locateip
{
    class funciones
    {
        public string getip(string buscar)
        {

            String code = "";
            String url = "http://whatismyipaddress.com/hostname-ip";
            String par = "DOMAINNAME="+buscar;
            String ip = "";

            HttpWebRequest nave = (HttpWebRequest)WebRequest.Create(url);

            nave.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
            nave.Method = "POST";
            nave.ContentType = "application/x-www-form-urlencoded";

            Stream anteantecode = nave.GetRequestStream();

            anteantecode.Write(Encoding.ASCII.GetBytes(par), 0, Encoding.ASCII.GetBytes(par).Length);
            anteantecode.Close();

            StreamReader antecode = new StreamReader(nave.GetResponse().GetResponseStream());
            code = antecode.ReadToEnd();

            Match regex = Regex.Match(code, "Lookup IP Address: <a href=(.*)>(.*)</a>", RegexOptions.IgnoreCase);

            if (regex.Success)
            {
                ip = regex.Groups[2].Value;
            }
            else
            {
                ip = "Error";
            }

            return ip;
        }

        public List<String> locateip(string ip)
        {
            string code = "";

            string city = "";
            string country = "";
            string state = "";

            WebClient nave = new WebClient();
            nave.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
            code = nave.DownloadString("http://www.melissadata.com/lookups/iplocation.asp?ipaddress=" + ip);

            Match regex = Regex.Match(code, "City</td><td align=(.*)><b>(.*)</b></td>", RegexOptions.IgnoreCase);

            if (regex.Success)
            {
                city = regex.Groups[2].Value;
            }
            else
            {
                city = "Error";
            }

            regex = Regex.Match(code, "Country</td><td align=(.*)><b>(.*)</b></td>", RegexOptions.IgnoreCase);

            if (regex.Success)
            {
                country = regex.Groups[2].Value;
            }
            else
            {
                country = "Error";
            }

            regex = Regex.Match(code, "State or Region</td><td align=(.*)><b>(.*)</b></td>", RegexOptions.IgnoreCase);

            if (regex.Success)
            {
                state = regex.Groups[2].Value;
            }
            else
            {
                state = "Error";
            }

            List<string> respuesta = new List<string> {};
            respuesta.Add(city);
            respuesta.Add(country);
            respuesta.Add(state);
            return respuesta;

        }

        public List<String> getdns(string ip)
        {

            string code = "";

            WebClient nave = new WebClient();
            nave.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
            code = nave.DownloadString("http://www.ip-adress.com/reverse_ip/" + ip);

            List<string> respuesta = new List<string> {};

            Match regex = Regex.Match(code, "whois/(.*?)\">Whois", RegexOptions.IgnoreCase);

            while (regex.Success)
            {
                respuesta.Add(regex.Groups[1].Value);
                regex = regex.NextMatch();
            }

            return respuesta;
        }

    }
}

// The End ?


Si lo quieren bajar lo pueden hacer de aca (https://sourceforge.net/projects/locateipx/).
Título: Re:[C#] LocateIP 0.2
Publicado por: ANTRAX en Julio 04, 2014, 05:20:37 PM
Muy bueno Doddy!!
Me gusta mucho la UI que le haces a tus programas!!

Felicitaciones por el soft!!

Saludos!
ANTRAX
Título: Re:[C#] LocateIP 0.2
Publicado por: BigBear en Julio 06, 2014, 03:00:19 PM
te gusta el skin ? , ajajaaja  , en otros foros me han dicho todo tipo de troleadas por el skin xD.
Título: Re:[C#] LocateIP 0.2
Publicado por: blackdrake en Julio 06, 2014, 03:08:35 PM
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
te gusta el skin ? , ajajaaja  , en otros foros me han dicho todo tipo de troleadas por el skin xD.

A mi también me gusta... jajaja
Título: Re:[C#] LocateIP 0.2
Publicado por: Bambinolas en Mayo 09, 2016, 07:29:25 PM
Buen aporte, saludos  :)
Título: Re:[C#] LocateIP 0.2
Publicado por: EddiFog en Mayo 27, 2016, 12:28:58 AM
Muy buena herramienta, gracias por el aporte! :D