Page 15 - DCAP202_Fundamentals of Web Programming
P. 15

Fundamentals of Web Programming




                    Notes          The order Preferred networks determines the order that Windows XP will automatically attempt
                                   when seeking to make a wireless/Internet connection. You can set this order to your preference,
                                   with the limitation that all infrastructure mode networks must appear ahead of all ad hoc mode
                                   networks in the Preferred list.

                                   Self Assessment

                                   Fill in the blanks:
                                   8.  ........................... splits the signal in the telephone wire in two: voice and broadband.

                                   9.  The ........................... tab allows you to access the set of "Available" networks.

                                   1.5 Client IP Address

                                   It's pretty common the need for a web application to be able to detect the IP address of a client.
                                   The IP address could be used either for statistic or authentication purposes.
                                   You can also use the IP address to block multiple logins with the same credentials. This could be
                                   useful for sites that offer content to users that have paid a subscription.

                                   1.5.1 Using the Code

                                   The code to do so is really easy, all you need to do is check a bunch of server variables. The good
                                   thing is that those variables are not platform specific, so an equivalent code could also work
                                   with PHP.
                                   Function  ClientIpAddress(ByVal  myRequest  As  HttpRequest)
                                          Dim  myIP  As  String  =  “”
                                          If  (myIP  =  “”)  Then
                                          myIP  =  myRequest.ServerVariables(“HTTP_CLIENT_IP”)
                                          If  (myIP  =  “”)  Then  myIP  =
                                          myRequest.ServerVariables(“HTTP_X_FORWARDED_FOR”)
                                          If  (myIP  =  “”)  Then  myIP  =
                                          myRequest.ServerVariables(“HTTP_X_FORWARDED”)
                                          If  (myIP  =  “”)  Then  myIP  =
                                          myRequest.ServerVariables(“HTTP_  X_CLUSTER_CLIENT_IP”)
                                          If  (myIP  =  “”)  Then
                                          myIP  =  myRequest.ServerVariables(“HTTP_FORWARDED_FOR”)
                                          If  (myIP  =  “”)  Then
                                          myIP  =  myRequest.ServerVariables(“HTTP_FORWARDED”)
                                          If  (myIP  =  “”)  Then
                                          myIP  =  myRequest.ServerVariables(“REMOTE_ADDR”)
                                     Return  myIP
                                   End  Function
                                   Sometimes though we do not have the actual IP address but we have the host name of the ISP
                                   provider of the client. The host name can be easily resolved into an IP address easily. Using the
                                   System.Net.Dns.GetHostEntry function we get a list of all the IP addresses this hostname resolves
                                   to.
                                   Function  Host2Ip(ByVal  HostName  As  String)  As  String
                                     Try
                                     Dim  myIPs  As  System.Net.IPHostEntry
                                     myIPs  =  System.Net.Dns.GetHostEntry(HostName)



          8                                 LOVELY PROFESSIONAL UNIVERSITY
   10   11   12   13   14   15   16   17   18   19   20