Routing table

dibrony

Member
Joined
Oct 23, 2010
Messages
6
Programming Experience
5-10
Hello everyone,

I would like to know how to get the IP routing table of a client that is accessing an aspx file via internet (written in Vb.net) to be used later on.
Actually when a client calls my aspx file, I want to register his IP (it should be an IP table, as I know), in order to be able to access him later on for data update ,I think this is called push notification or push message.

Anyone can help ?

Thanks
Rony
 
If you're stuck on getting the client's IP address here's this:
Imports System
Imports System.Web

Module IP
    Function GetIPAddress() As String
        Return GetIPAddress(New HttpRequestWrapper(HttpContext.Current.Request))
    End Function

    Friend Function GetIPAddress(ByVal request As HttpRequestBase) As String
        Dim forwarded As String = request.Headers("Forwarded")

        If Not String.IsNullOrEmpty(forwarded) Then

            For Each segment As String In forwarded.Split(","c)(0).Split(";"c)
                Dim pair As String() = segment.Trim().Split("="c)

                If pair.Length = 2 AndAlso pair(0).Equals("for", StringComparison.OrdinalIgnoreCase) Then
                    Dim ip As String = pair(1).Trim(""""c)
                    Dim left As Integer = ip.IndexOf("["c), right As Integer = ip.IndexOf("]"c)

                    If left = 0 AndAlso right > 0 Then
                        Return ip.Substring(1, right - 1)
                    End If

                    Dim colon As Integer = ip.IndexOf(":"c)

                    If colon <> -1 Then
                        Return ip.Substring(0, colon)
                    End If

                    Return ip
                End If
            Next
        End If

        Dim xForwardedFor As String = request.Headers("X-Forwarded-For")

        If Not String.IsNullOrEmpty(xForwardedFor) Then
            Return xForwardedFor.Split(","c)(0)
        End If

        Return request.UserHostAddress
    End Function
End Module
Just add it to your project as a new class and call it:
IP.GetIPAddress()
As for the push notifications that's something I haven't had a need to learn how to do yet.
 
Thanks for your help.
However, what library should I import as the types "HttpRequestWrapper" and "HttpRequestBase" are not defined.

Actually I have the below libraries in my project and still not defined:

Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports System.Collections.Specialized
Imports System.Net
Imports System.Text
Imports System.IO
 
Last edited:
Thanks for your help.
However, what library should I import as the types "HttpRequestWrapper" and "HttpRequestBase" are not defined.

That's not a question that you ever need to ask. Every public type in the Framework is documented and the documentation for every type specifies what assembly it is declared in and what namespace it's a member of. You also ought to learn the difference between a namespace and an assembly because that list you provided are not libraries. I suggest that you follow the Blog link in my signature below and check out my post on Assemblies & Namespaces.
 
Back
Top