extract IP address

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepjain4u
    New Member
    • Sep 2007
    • 2

    extract IP address

    hi
    i want to extract ip address. like we have ip address 127.0.0.1
    i want to extract ip address in 4 different variable like ip1=127 ip2=0,ip3=0 ip4=1

    i have get ip address on label. like

    Label1.Text = Request.UserHos tAddress
    how can i extract ip
    pls help me
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Try to find out the position of . in the IP address using corresponding substring, instring and length functions of the language.

    Comment

    • shiponeye1
      New Member
      • Aug 2007
      • 8

      #3
      in C# you may done it through the following code

      string sIPAddress=labe l2.Text;

      string[] sExtractIPAddre ss=sIPAddress.S plit('.');

      string IP1=sExtractIPA ddress[0];
      string IP2=sExtractIPA ddress[1];
      string IP3=sExtractIPA ddress[2];
      string IP4=sExtractIPA ddress[3];

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        Looks the same in VB:
        Code:
        Dim s As String = Request.UserHostAddress
        Dim sExtractIPAddress As String() = s.Split(".".ToCharArray)
        Dim IP1 As String = sExtractIPAddress(0)
        Dim IP2 As String = sExtractIPAddress(1)
        Dim IP3 As String = sExtractIPAddress(2)
        Dim IP4 As String = sExtractIPAddress(3)

        Comment

        • sandeepjain4u
          New Member
          • Sep 2007
          • 2

          #5
          thank you buddy for helping

          Originally posted by SammyB
          Looks the same in VB:
          Code:
          Dim s As String = Request.UserHostAddress
          Dim sExtractIPAddress As String() = s.Split(".".ToCharArray)
          Dim IP1 As String = sExtractIPAddress(0)
          Dim IP2 As String = sExtractIPAddress(1)
          Dim IP3 As String = sExtractIPAddress(2)
          Dim IP4 As String = sExtractIPAddress(3)

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Actually the IPAddress class has a property that returns a byte[4]. Each of the 4 bytes represents one of the set of numbers in the address.

            Comment

            Working...