Click here to Skip to main content
11,570,945 members (63,448 online)

iyalarasi asked:

Open original thread
I want to convert the following vb.net code to be written in c#. Please any one help me

Public Shared Function RestrictIPAddress(ByVal strRemoteAddress As String) As Boolean
 
       'RestrictIPAddress = True

       ' If UCase(ConfigurationSettings.AppSettings("RestrictIPMode")) = "ON" Then
       RestrictIPAddress = False
 
       Dim ObjTemp As Object
       Dim ArrReStrictIP1 As String, ArrReStrictIP2 As String
       Dim ArrRemoteIP(4) As Integer, ArrResIP1(4) As Integer, ArrResIP2(4) As Integer
       Dim i As Int16
 
       ObjTemp = Split(ConfigurationManager.AppSettings("RestrictIPAddress"), "to")
       If UBound(ObjTemp) > 0 Then
           ArrReStrictIP1 = CStr(ObjTemp(0))
           ArrReStrictIP2 = CStr(ObjTemp(1))
       End If
 
       ObjTemp = Split(strRemoteAddress, ".")
       For i = 0 To UBound(ObjTemp)
           ArrRemoteIP(i) = CInt(ObjTemp(i))
       Next
       ObjTemp = Split(ArrReStrictIP1, ".")
       For i = 0 To UBound(ObjTemp)
           ArrResIP1(i) = CInt(ObjTemp(i))
       Next
 
       ObjTemp = Split(ArrReStrictIP2, ".")
       For i = 0 To UBound(ObjTemp)
           ArrResIP2(i) = CInt(ObjTemp(i))
       Next
       If (ArrRemoteIP(0) >= ArrResIP1(0) And ArrRemoteIP(0) <= ArrResIP2(0)) Then
           If (ArrRemoteIP(1) >= ArrResIP1(1) And ArrRemoteIP(1) <= ArrResIP2(1)) Then
               If (ArrRemoteIP(1) >= ArrResIP1(1) And ArrRemoteIP(1) <= ArrResIP2(1)) And (ArrRemoteIP(2) >= ArrResIP1(2) And ArrRemoteIP(2) <= ArrResIP2(2)) Then
                   If (ArrRemoteIP(1) >= ArrResIP1(1) And ArrRemoteIP(1) <= ArrResIP2(1)) And (ArrRemoteIP(2) >= ArrResIP1(2) And ArrRemoteIP(2) <= ArrResIP2(2)) And (ArrRemoteIP(3) >= ArrResIP1(3) And ArrRemoteIP(3) <= ArrResIP2(3)) Then
                       Return True
                   End If
               End If
           End If
       End If
       '  End If

   End Function

Please help me soon. I want to finih this task today?
Tags: ASP.NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100