Showing posts with label ASP.Net with socket and networking. Show all posts
Showing posts with label ASP.Net with socket and networking. Show all posts

Tuesday, February 14, 2012

Port scan using ASP.Net

Port scan using ASP.NET




Step 1)Check your internet connection.

Step 2) Put following code in your ASP.Net page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="socket.aspx.cs" Inherits="socket" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Start port:-&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        End port:- &nbsp;
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
        Enter URL:-<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Scan" Width="66px" /><br />
        <br />
        <asp:ListBox ID="ListBox1" runat="server" Height="129px" Width="230px"></asp:ListBox><br />
        <br />
   
    </div>
    </form>
</body>
</html>


Step 3)Write below code in your code behind of ASP.Net page


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Net.Sockets;

public partial class socket : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        Int32 start = Convert.ToInt32(this.TextBox1.Text);
        Int32 end = Convert.ToInt32(this.TextBox2.Text);
        string url = Convert.ToString(this.TextBox3.Text);

        IPHostEntry hostname1 = Dns.GetHostByName(url);
        IPAddress[] ip1 = hostname1.AddressList;

        string ip = ip1[0].ToString();

        TcpClient abc = new TcpClient();
        for (int i = start; i < end; i++)
        {

            try
            {
                abc.Connect(ip, i);
                this.ListBox1.Items.Add("Port" + Convert.ToSingle(i) + "open");

            }
            catch (Exception ex)
            {
                this.ListBox1.Items.Add("Port" + Convert.ToString(i) + "Close");
            }
        }

    }
}

Fetch a web page from server using ASP.Net



Fetch a web page from web server
 

Step 1) Make sure internet connection of your machine is available

Step 2)Put the following code in your ASP.Net Page
            (It will take some time to exhicute the programe)

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;


public partial class socket : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            StreamReader inStream;
            WebRequest webRequest;
            WebResponse webresponse;
            webRequest = WebRequest.Create("http://www.yahoo.com");
            webresponse = webRequest.GetResponse();
            inStream = new StreamReader(webresponse.GetResponseStream());
            Response.Write(inStream.ReadToEnd());
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

    }
}

Display IP address of server using ASP.Net


How to display IP address of Server using ASP.NET



Step 1) Make sure internet connection of your machine is available

Step 2)Put the following code in your ASP.Net Page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;


public partial class socket : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            IPHostEntry hostname1 = Dns.GetHostByName("www.google.com");
            IPHostEntry hostname2 = Dns.GetHostByName("www.yahoo.com");
            IPAddress[] ip1 = hostname1.AddressList;
            IPAddress[] ip2 = hostname2.AddressList;

            Response.Write("Google.com:-"+ ip1[0].ToString() + "<br>");
            Response.Write("Yahoo.com"+ ip2[0].ToString());
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}