Long2IP Function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jack

    Long2IP Function?

    Hello,

    I need a long number to IP Address Convertion Function.

    Take

    3349551105

    to

    199.166.24.1

    Please let me know if anyone has such a function.

    Thanks in advance for your help,

    Jack


  • Tom Shelton

    #2
    Re: Long2IP Function?

    On 2005-05-31, Jack <jouin@webfoxma il.com> wrote:[color=blue]
    > Hello,
    >
    > I need a long number to IP Address Convertion Function.
    >
    > Take
    >
    > 3349551105
    >
    > to
    >
    > 199.166.24.1
    >
    > Please let me know if anyone has such a function.
    >
    > Thanks in advance for your help,
    >
    > Jack[/color]

    Dim IP As String = New IPAddress (myLongValue).T oString ()
    --
    Tom Shelton [MVP]

    Comment

    • Supra

      #3
      Re: Long2IP Function?

      r u using irc chat?


      Jack wrote:
      [color=blue]
      >Hello,
      >
      >I need a long number to IP Address Convertion Function.
      >
      >Take
      >
      >3349551105
      >
      >to
      >
      >199.166.24.1
      >
      >Please let me know if anyone has such a function.
      >
      >Thanks in advance for your help,
      >
      >Jack
      >
      >
      >
      >[/color]

      Comment

      • Jack

        #4
        Re: Long2IP Function?

        Hello Tom,

        Thanks, it works great. There is one problem it is printing the IP address
        backwords.

        199.166.24.1

        Comes out

        1.24.166.199

        Please let me know if how to fix this.

        Thank you for all of your help,

        Jack

        "Tom Shelton" <tshelton@YOUKN OWTHEDRILLcomca st.net> wrote in message
        news:%23fAbsqZZ FHA.584@TK2MSFT NGP15.phx.gbl.. .[color=blue]
        > On 2005-05-31, Jack <jouin@webfoxma il.com> wrote:[color=green]
        >> Hello,
        >>
        >> I need a long number to IP Address Convertion Function.
        >>
        >> Take
        >>
        >> 3349551105
        >>
        >> to
        >>
        >> 199.166.24.1
        >>
        >> Please let me know if anyone has such a function.
        >>
        >> Thanks in advance for your help,
        >>
        >> Jack[/color]
        >
        > Dim IP As String = New IPAddress (myLongValue).T oString ()
        > --
        > Tom Shelton [MVP][/color]


        Comment

        • Tom Shelton

          #5
          Re: Long2IP Function?

          On 2005-06-01, Jack <jouin@webfoxma il.com> wrote:[color=blue]
          > Hello Tom,
          >
          > Thanks, it works great. There is one problem it is printing the IP address
          > backwords.
          >
          > 199.166.24.1
          >
          > Comes out
          >
          > 1.24.166.199
          >
          > Please let me know if how to fix this.
          >
          > Thank you for all of your help,
          >
          > Jack[/color]

          Ooops... Try this:

          Dim IP As String = New IPAddress _
          (IPAddress.Netw orkToHostOrder (MyLongValue)). ToString()


          --
          Tom Shelton [MVP]

          Comment

          • Jack

            #6
            Re: Long2IP Function?

            Hello Tom,

            Thanks for the fast response. I am getting this error using the new
            command:

            An unhandled exception of type 'System.Argumen tOutOfRangeExce ption' occurred
            in system.dll

            Please let me know what I am doing wrong.

            Thanks for your help and time,

            Jack

            "Tom Shelton" <tshelton@YOUKN OWTHEDRILLcomca st.net> wrote in message
            news:ObNWQZlZFH A.612@TK2MSFTNG P12.phx.gbl...[color=blue]
            > On 2005-06-01, Jack <jouin@webfoxma il.com> wrote:[color=green]
            >> Hello Tom,
            >>
            >> Thanks, it works great. There is one problem it is printing the IP
            >> address
            >> backwords.
            >>
            >> 199.166.24.1
            >>
            >> Comes out
            >>
            >> 1.24.166.199
            >>
            >> Please let me know if how to fix this.
            >>
            >> Thank you for all of your help,
            >>
            >> Jack[/color]
            >
            > Ooops... Try this:
            >
            > Dim IP As String = New IPAddress _
            > (IPAddress.Netw orkToHostOrder (MyLongValue)). ToString()
            >
            >
            > --
            > Tom Shelton [MVP][/color]


            Comment

            • Tom Shelton

              #7
              Re: Long2IP Function?

              On 2005-06-01, Jack <jouin@webfoxma il.com> wrote:[color=blue]
              > Hello Tom,
              >
              > Thanks for the fast response. I am getting this error using the new
              > command:
              >
              > An unhandled exception of type 'System.Argumen tOutOfRangeExce ption' occurred
              > in system.dll
              >
              > Please let me know what I am doing wrong.
              >
              > Thanks for your help and time,
              >
              > Jack[/color]

              Hmm... Jack - let me play with this some more (if no one else jumps in).
              This is what I get for not testing my responses :)

              --
              Tom Shelton [MVP]

              Comment

              • Tom Shelton

                #8
                Re: Long2IP Function?

                In article <OMqUgqlZFHA.34 00@tk2msftngp13 .phx.gbl>, Jack wrote:[color=blue]
                > Hello Tom,
                >
                > Thanks for the fast response. I am getting this error using the new
                > command:
                >
                > An unhandled exception of type 'System.Argumen tOutOfRangeExce ption' occurred
                > in system.dll
                >
                > Please let me know what I am doing wrong.
                >
                > Thanks for your help and time,
                >
                > Jack
                >
                > "Tom Shelton" <tshelton@YOUKN OWTHEDRILLcomca st.net> wrote in message
                > news:ObNWQZlZFH A.612@TK2MSFTNG P12.phx.gbl...[color=green]
                >> On 2005-06-01, Jack <jouin@webfoxma il.com> wrote:[color=darkred]
                >>> Hello Tom,
                >>>
                >>> Thanks, it works great. There is one problem it is printing the IP
                >>> address
                >>> backwords.
                >>>
                >>> 199.166.24.1
                >>>
                >>> Comes out
                >>>
                >>> 1.24.166.199
                >>>
                >>> Please let me know if how to fix this.
                >>>
                >>> Thank you for all of your help,
                >>>
                >>> Jack[/color]
                >>
                >> Ooops... Try this:
                >>
                >> Dim IP As String = New IPAddress _
                >> (IPAddress.Netw orkToHostOrder (MyLongValue)). ToString()
                >>[/color][/color]

                Ok... One more shot :)

                Option Strict On
                Option Explicit On

                Imports System.Net

                Module Module1

                Sub Main()
                Dim tmpIP As New IPAddress(33495 51105)
                Dim bytes() As Byte = tmpIP.GetAddres sBytes()
                Array.Reverse(b ytes)
                Dim addr As Long = BitConverter.To Int32(bytes, 0)
                Console.WriteLi ne(New IPAddress(addr) .ToString())
                Console.ReadLin e()
                End Sub

                End Module


                --
                Tom Shelton [MVP]

                Comment

                • Jack

                  #9
                  Re: Long2IP Function?

                  Thank you very much!!!

                  Jack

                  "Tom Shelton" <tom@YOUKNOWTHE DRILLmtogden.co m> wrote in message
                  news:efFnq1vZFH A.3120@TK2MSFTN GP12.phx.gbl...[color=blue]
                  > In article <OMqUgqlZFHA.34 00@tk2msftngp13 .phx.gbl>, Jack wrote:[color=green]
                  >> Hello Tom,
                  >>
                  >> Thanks for the fast response. I am getting this error using the new
                  >> command:
                  >>
                  >> An unhandled exception of type 'System.Argumen tOutOfRangeExce ption'
                  >> occurred
                  >> in system.dll
                  >>
                  >> Please let me know what I am doing wrong.
                  >>
                  >> Thanks for your help and time,
                  >>
                  >> Jack
                  >>
                  >> "Tom Shelton" <tshelton@YOUKN OWTHEDRILLcomca st.net> wrote in message
                  >> news:ObNWQZlZFH A.612@TK2MSFTNG P12.phx.gbl...[color=darkred]
                  >>> On 2005-06-01, Jack <jouin@webfoxma il.com> wrote:
                  >>>> Hello Tom,
                  >>>>
                  >>>> Thanks, it works great. There is one problem it is printing the IP
                  >>>> address
                  >>>> backwords.
                  >>>>
                  >>>> 199.166.24.1
                  >>>>
                  >>>> Comes out
                  >>>>
                  >>>> 1.24.166.199
                  >>>>
                  >>>> Please let me know if how to fix this.
                  >>>>
                  >>>> Thank you for all of your help,
                  >>>>
                  >>>> Jack
                  >>>
                  >>> Ooops... Try this:
                  >>>
                  >>> Dim IP As String = New IPAddress _
                  >>> (IPAddress.Netw orkToHostOrder (MyLongValue)). ToString()
                  >>>[/color][/color]
                  >
                  > Ok... One more shot :)
                  >
                  > Option Strict On
                  > Option Explicit On
                  >
                  > Imports System.Net
                  >
                  > Module Module1
                  >
                  > Sub Main()
                  > Dim tmpIP As New IPAddress(33495 51105)
                  > Dim bytes() As Byte = tmpIP.GetAddres sBytes()
                  > Array.Reverse(b ytes)
                  > Dim addr As Long = BitConverter.To Int32(bytes, 0)
                  > Console.WriteLi ne(New IPAddress(addr) .ToString())
                  > Console.ReadLin e()
                  > End Sub
                  >
                  > End Module
                  >
                  >
                  > --
                  > Tom Shelton [MVP][/color]


                  Comment

                  • Jack

                    #10
                    Re: Long2IP Function?

                    Hello,

                    I have made a function out off the info:

                    Function IPNumber2IPAddr ess(ByVal IP As Long) As String

                    Dim tmpIP As New System.Net.IPAd dress(IP)

                    Dim bytes() As Byte = tmpIP.GetAddres sBytes()

                    Array.Reverse(b ytes)

                    Dim addr As Long = BitConverter.To Int32(bytes, 0)

                    IPNumber2IPAddr ess = New System.Net.IPAd dress(addr).ToS tring()

                    End Function

                    It work most of the time, but when the IP Number is : 1167456428

                    I get an 'ArgumentOutOfR angeException' Error.

                    Any help would be great!!

                    Thanks,

                    Jack


                    "Jack" <jouin@webfoxma il.com> wrote in message
                    news:eV%23JKZxZ FHA.3132@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                    > Thank you very much!!!
                    >
                    > Jack
                    >
                    > "Tom Shelton" <tom@YOUKNOWTHE DRILLmtogden.co m> wrote in message
                    > news:efFnq1vZFH A.3120@TK2MSFTN GP12.phx.gbl...[color=green]
                    >> In article <OMqUgqlZFHA.34 00@tk2msftngp13 .phx.gbl>, Jack wrote:[color=darkred]
                    >>> Hello Tom,
                    >>>
                    >>> Thanks for the fast response. I am getting this error using the new
                    >>> command:
                    >>>
                    >>> An unhandled exception of type 'System.Argumen tOutOfRangeExce ption'
                    >>> occurred
                    >>> in system.dll
                    >>>
                    >>> Please let me know what I am doing wrong.
                    >>>
                    >>> Thanks for your help and time,
                    >>>
                    >>> Jack
                    >>>
                    >>> "Tom Shelton" <tshelton@YOUKN OWTHEDRILLcomca st.net> wrote in message
                    >>> news:ObNWQZlZFH A.612@TK2MSFTNG P12.phx.gbl...
                    >>>> On 2005-06-01, Jack <jouin@webfoxma il.com> wrote:
                    >>>>> Hello Tom,
                    >>>>>
                    >>>>> Thanks, it works great. There is one problem it is printing the IP
                    >>>>> address
                    >>>>> backwords.
                    >>>>>
                    >>>>> 199.166.24.1
                    >>>>>
                    >>>>> Comes out
                    >>>>>
                    >>>>> 1.24.166.199
                    >>>>>
                    >>>>> Please let me know if how to fix this.
                    >>>>>
                    >>>>> Thank you for all of your help,
                    >>>>>
                    >>>>> Jack
                    >>>>
                    >>>> Ooops... Try this:
                    >>>>
                    >>>> Dim IP As String = New IPAddress _
                    >>>> (IPAddress.Netw orkToHostOrder (MyLongValue)). ToString()
                    >>>>[/color]
                    >>
                    >> Ok... One more shot :)
                    >>
                    >> Option Strict On
                    >> Option Explicit On
                    >>
                    >> Imports System.Net
                    >>
                    >> Module Module1
                    >>
                    >> Sub Main()
                    >> Dim tmpIP As New IPAddress(33495 51105)
                    >> Dim bytes() As Byte = tmpIP.GetAddres sBytes()
                    >> Array.Reverse(b ytes)
                    >> Dim addr As Long = BitConverter.To Int32(bytes, 0)
                    >> Console.WriteLi ne(New IPAddress(addr) .ToString())
                    >> Console.ReadLin e()
                    >> End Sub
                    >>
                    >> End Module
                    >>
                    >>
                    >> --
                    >> Tom Shelton [MVP][/color]
                    >
                    >[/color]


                    Comment

                    • Larry Lard

                      #11
                      Re: Long2IP Function?



                      Jack wrote:[color=blue]
                      > Hello,
                      >
                      > I have made a function out off the info:
                      >
                      > Function IPNumber2IPAddr ess(ByVal IP As Long) As String
                      >
                      > Dim tmpIP As New System.Net.IPAd dress(IP)
                      >
                      > Dim bytes() As Byte = tmpIP.GetAddres sBytes()
                      >
                      > Array.Reverse(b ytes)
                      >
                      > Dim addr As Long = BitConverter.To Int32(bytes, 0)
                      >
                      > IPNumber2IPAddr ess = New System.Net.IPAd dress(addr).ToS tring()
                      >
                      > End Function
                      >
                      > It work most of the time, but when the IP Number is : 1167456428
                      >
                      > I get an 'ArgumentOutOfR angeException' Error.
                      >
                      > Any help would be great!![/color]

                      Change

                      Dim addr As Long = BitConverter.To Int32(bytes, 0)

                      to

                      Dim addr As Long = Convert.ToInt64 (BitConverter.T oUInt32(bytes, 0))

                      as with high IP Numbers you were getting negative Integers from
                      ToInt32.

                      --
                      Larry Lard
                      Replies to group please

                      Comment

                      Working...