Tuesday 9 June 2015

How to get my public, External or ISP IP address in c# .net ?

Here in this post I wrote c# example to get  public, external and ISP IP address.

Nameapce Required :-

using System.Net;

using System.Text.RegularExpressions;


Your request will be going to below site addres and it will return your IP addres. You must be connected with internet.

http://checkip.dyndns.org


Code Example:-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;

namespace DempApp
{
  class GetIpAddress
   {
     static void Main(string[] args)
     {
       try
        {
         string externalIP;
         Console.WriteLine("\nPlease wait...");
         externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
         externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")).Matches(externalIP)[0].ToString();
         Console.WriteLine("\n Your public IP address:- {0}", externalIP);
          Console.ReadKey();
        }
       catch
        {
          Console.WriteLine("please try Again!");
          Console.ReadKey();
         }

       }
    }

}


Output:-













This very frequently  used code in to track visitor's IP addres.I hope you enjoyed this post. Please comments your feedback and questions.

Sunday 7 June 2015

How to Spilt string sql server ?

In this post I wrote a SQL function to split string in sql server. In most of cases we need to split sql string.


Creating sql function:-

CREATE FUNCTION [dbo].[fnSplitSqlString]
(
    @string nvarchar(MAX),
    @delimiter char(1)
)

 RETURNS @output table
  (
   SplitData nvarchar(MAX)
  )

BEGIN
    DECLARE @start int, @end int
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
    WHILE @start < LEN(@string) + 1 BEGIN
        IF @end =
            SET @end = LEN(@string) + 1
      
        INSERT INTO @output (splitdata) 
        VALUES(SUBSTRING(@string, @start, @end - @start))
        SET @start = @end + 1
        SET @end = CHARINDEX(@delimiter, @string, @start)
       
    END
    RETURN
END

Calling above function :-


Select * from [dbo].fnSplitSqlString('SQL$ASP.NET$WCF$JQuery$c#.NET','$')

Output:-



















I hope you enjoyed this post. Please comments your feedback and questions.