├── dll
└── IP2LocationHTTPModule.dll
├── IP2LocationHTTPModule
├── IP2LocationHTTPModule
│ ├── packages.config
│ ├── IP2LocationHTTPModule.snk
│ ├── merged
│ │ └── IP2LocationHTTPModule.dll
│ ├── My Project
│ │ ├── Settings.settings
│ │ ├── Application.Designer.vb
│ │ ├── Application.myapp
│ │ ├── AssemblyInfo.vb
│ │ ├── Resources.Designer.vb
│ │ ├── Settings.Designer.vb
│ │ └── Resources.resx
│ ├── LogDebug.vb
│ ├── XML.vb
│ ├── MetaData.vb
│ ├── IP2LocationHTTPModule.vbproj
│ ├── LookupClass.vb
│ ├── IP2LocationHTTPModule.vb
│ └── IP2Location.vb
└── IP2LocationHTTPModule.sln
├── IP2Location-config.xml
├── LICENSE
├── .gitignore
└── README.md
/dll/IP2LocationHTTPModule.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ip2location/ip2location-httpmodule/HEAD/dll/IP2LocationHTTPModule.dll
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/IP2LocationHTTPModule.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ip2location/ip2location-httpmodule/HEAD/IP2LocationHTTPModule/IP2LocationHTTPModule/IP2LocationHTTPModule.snk
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/merged/IP2LocationHTTPModule.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ip2location/ip2location-httpmodule/HEAD/IP2LocationHTTPModule/IP2LocationHTTPModule/merged/IP2LocationHTTPModule.dll
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.18444
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 | false
5 | 0
6 | true
7 | 0
8 | 1
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "IP2LocationHTTPModule", "IP2LocationHTTPModule\IP2LocationHTTPModule.vbproj", "{2825F3C9-6057-488F-8353-CE9C417CA5FE}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {2825F3C9-6057-488F-8353-CE9C417CA5FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {2825F3C9-6057-488F-8353-CE9C417CA5FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {2825F3C9-6057-488F-8353-CE9C417CA5FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {2825F3C9-6057-488F-8353-CE9C417CA5FE}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/IP2Location-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | bin\your_database_file.BIN
5 |
6 |
7 | HTTP_X_FORWARDED_FOR
8 | True
9 |
10 |
11 |
12 | .*\.php
13 | NOT IN
14 | US,CA,MY
15 | True
16 |
17 |
18 |
19 |
20 | .*/Default\.aspx
21 | http://www.google.sg
22 | IN
23 | MY,SG,AU
24 | True
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2025 IP2Location
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
21 |
22 |
23 | ' Version information for an assembly consists of the following four values:
24 | '
25 | ' Major Version
26 | ' Minor Version
27 | ' Build Number
28 | ' Revision
29 | '
30 | ' You can specify all the values or you can default the Build and Revision Numbers
31 | ' by using the '*' as shown below:
32 | '
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/LogDebug.vb:
--------------------------------------------------------------------------------
1 | '---------------------------------------------------------------------------
2 | ' Author : IP2Location.com
3 | ' URL : http://www.ip2location.com
4 | ' Email : sales@ip2location.com
5 | '
6 | ' Copyright (c) 2002-2025 IP2Location.com
7 | '---------------------------------------------------------------------------
8 |
9 | Imports System.IO
10 |
11 | Public Class LogDebug
12 | Public Shared Sub WriteLog(ByVal mymesg As String)
13 | Dim myfilename As String = System.AppDomain.CurrentDomain.BaseDirectory & "errLog.txt"
14 | Dim fs As FileStream = Nothing
15 | Dim objWriter As StreamWriter = Nothing
16 |
17 | If File.Exists(myfilename) Then
18 | Try
19 | fs = New FileStream(myfilename, FileMode.Append, FileAccess.Write, FileShare.Write)
20 | objWriter = New StreamWriter(fs)
21 | objWriter.WriteLine(Now & ": " & mymesg)
22 | Catch ex As Exception
23 | 'just fail silently
24 | Finally
25 | If objWriter IsNot Nothing Then
26 | objWriter.Close()
27 | End If
28 | If fs IsNot Nothing Then
29 | fs.Close()
30 | End If
31 | End Try
32 | End If
33 | End Sub
34 | End Class
35 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.18444
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 | Imports System
15 |
16 | Namespace My.Resources
17 |
18 | 'This class was auto-generated by the StronglyTypedResourceBuilder
19 | 'class via a tool like ResGen or Visual Studio.
20 | 'To add or remove a member, edit your .ResX file then rerun ResGen
21 | 'with the /str option, or rebuild your VS project.
22 | '''
23 | ''' A strongly-typed resource class, for looking up localized strings, etc.
24 | '''
25 | _
29 | Friend Module Resources
30 |
31 | Private resourceMan As Global.System.Resources.ResourceManager
32 |
33 | Private resourceCulture As Global.System.Globalization.CultureInfo
34 |
35 | '''
36 | ''' Returns the cached ResourceManager instance used by this class.
37 | '''
38 | _
39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
40 | Get
41 | If Object.ReferenceEquals(resourceMan, Nothing) Then
42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("IP2Location.Resources", GetType(Resources).Assembly)
43 | resourceMan = temp
44 | End If
45 | Return resourceMan
46 | End Get
47 | End Property
48 |
49 | '''
50 | ''' Overrides the current thread's CurrentUICulture property for all
51 | ''' resource lookups using this strongly typed resource class.
52 | '''
53 | _
54 | Friend Property Culture() As Global.System.Globalization.CultureInfo
55 | Get
56 | Return resourceCulture
57 | End Get
58 | Set
59 | resourceCulture = value
60 | End Set
61 | End Property
62 | End Module
63 | End Namespace
64 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/My Project/Settings.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.18444
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | _
20 | Partial Friend NotInheritable Class MySettings
21 | Inherits Global.System.Configuration.ApplicationSettingsBase
22 |
23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
24 |
25 | #Region "My.Settings Auto-Save Functionality"
26 | #If _MyType = "WindowsForms" Then
27 | Private Shared addedHandler As Boolean
28 |
29 | Private Shared addedHandlerLockObject As New Object
30 |
31 | _
32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
33 | If My.Application.SaveMySettingsOnExit Then
34 | My.Settings.Save()
35 | End If
36 | End Sub
37 | #End If
38 | #End Region
39 |
40 | Public Shared ReadOnly Property [Default]() As MySettings
41 | Get
42 |
43 | #If _MyType = "WindowsForms" Then
44 | If Not addedHandler Then
45 | SyncLock addedHandlerLockObject
46 | If Not addedHandler Then
47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
48 | addedHandler = True
49 | End If
50 | End SyncLock
51 | End If
52 | #End If
53 | Return defaultInstance
54 | End Get
55 | End Property
56 | End Class
57 | End Namespace
58 |
59 | Namespace My
60 |
61 | _
64 | Friend Module MySettingsProperty
65 |
66 | _
67 | Friend ReadOnly Property Settings() As Global.IP2Location.My.MySettings
68 | Get
69 | Return Global.IP2Location.My.MySettings.Default
70 | End Get
71 | End Property
72 | End Module
73 | End Namespace
74 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/XML.vb:
--------------------------------------------------------------------------------
1 | '---------------------------------------------------------------------------
2 | ' Author : IP2Location.com
3 | ' URL : http://www.ip2location.com
4 | ' Email : sales@ip2location.com
5 | '
6 | ' Copyright (c) 2002-2025 IP2Location.com
7 | '---------------------------------------------------------------------------
8 |
9 | Imports System.Xml
10 | Imports System.Xml.Serialization
11 |
12 | 'NOTE: The XMLRootAttribute and XMLElement are for renaming the XML output tags.
13 |
14 |
15 | Public Class IP2LocationConfig
16 | Public Settings As Settings
17 |
18 |
20 | Public ByPassIPs() As ByPassIP
21 |
22 |
24 | Public BlockRules() As BlockRule
25 |
26 |
28 | Public RedirectRules() As RedirectRule
29 | End Class
30 |
31 | Public Class Settings
32 |
33 | Public BINFile As String
34 |
35 |
36 | Public CompanyName As String
37 |
38 |
39 | Public LicenseKey As String
40 |
41 |
42 | Public CustomIPServerVariable As String
43 |
44 |
45 | Public EnabledServerVariable As Boolean
46 |
47 | ' since we have to accept case-insensitive "true" & "false", no choice but to do this
48 |
49 | Public Property EnabledServerVariableStr() As String
50 | Get
51 | EnabledServerVariableStr = IIf(EnabledServerVariable, "True", "False")
52 | End Get
53 | Set(ByVal Value As String)
54 | EnabledServerVariable = XmlConvert.ToBoolean(Value.ToLower.Trim()) 'only "1" or "0" or "true" or "false" are accepted
55 | End Set
56 | End Property
57 | End Class
58 |
59 | Public Class ByPassIP
60 | Public IP As String
61 | End Class
62 |
63 | Public Class BlockRule
64 |
65 | Public Enabled As Boolean
66 |
67 | ' since we have to accept case-insensitive "true" & "false", no choice but to do this
68 |
69 | Public Property EnabledStr() As String
70 | Get
71 | EnabledStr = IIf(Enabled, "True", "False")
72 | End Get
73 | Set(ByVal Value As String)
74 | Enabled = XmlConvert.ToBoolean(Value.ToLower.Trim()) 'only "1" or "0" or "true" or "false" are accepted
75 | End Set
76 | End Property
77 |
78 |
79 | Public FromURL As String
80 | Public Comparison As String
81 | Public Countries As String
82 | End Class
83 |
84 | Public Class RedirectRule
85 |
86 |
87 | Public Enabled As Boolean
88 |
89 | ' since we have to accept case-insensitive "true" & "false", no choice but to do this
90 |
91 | Public Property EnabledStr() As String
92 | Get
93 | EnabledStr = IIf(Enabled, "True", "False")
94 | End Get
95 | Set(ByVal Value As String)
96 | Enabled = XmlConvert.ToBoolean(Value.ToLower.Trim()) 'only "1" or "0" or "true" or "false" are accepted
97 | End Set
98 | End Property
99 |
100 |
101 | Public FromURL As String
102 |
103 | Public ToURL As String
104 | Public Comparison As String
105 | Public Countries As String
106 | End Class
107 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/MetaData.vb:
--------------------------------------------------------------------------------
1 | '---------------------------------------------------------------------------
2 | ' Author : IP2Location.com
3 | ' URL : http://www.ip2location.com
4 | ' Email : sales@ip2location.com
5 | '
6 | ' Copyright (c) 2002-2025 IP2Location.com
7 | '---------------------------------------------------------------------------
8 | Friend Class MetaData
9 | Dim _BaseAddr As Integer = 0
10 | Dim _DBCount As Integer = 0
11 | Dim _DBColumn As Integer = 0
12 | Dim _DBType As Integer = 0
13 | Dim _DBDay As Integer = 1
14 | Dim _DBMonth As Integer = 1
15 | Dim _DBYear As Integer = 1
16 | Dim _BaseAddrIPv6 As Integer = 0
17 | Dim _DBCountIPv6 As Integer = 0
18 | Dim _OldBIN As Boolean = False
19 | Dim _Indexed As Boolean = False
20 | Dim _IndexedIPv6 As Boolean = False
21 | Dim _IndexBaseAddr As Integer = 0
22 | Dim _IndexBaseAddrIPv6 As Integer = 0
23 | Dim _ProductCode As Integer = 0
24 | Dim _ProductType As Integer = 0
25 | Dim _FileSize As Integer = 0
26 |
27 | Public Property BaseAddr() As Integer
28 | Get
29 | Return _BaseAddr
30 | End Get
31 | Set(ByVal Value As Integer)
32 | _BaseAddr = Value
33 | End Set
34 | End Property
35 |
36 | Public Property DBCount() As Integer
37 | Get
38 | Return _DBCount
39 | End Get
40 | Set(ByVal Value As Integer)
41 | _DBCount = Value
42 | End Set
43 | End Property
44 |
45 | Public Property DBColumn() As Integer
46 | Get
47 | Return _DBColumn
48 | End Get
49 | Set(ByVal Value As Integer)
50 | _DBColumn = Value
51 | End Set
52 | End Property
53 |
54 | Public Property DBType() As Integer
55 | Get
56 | Return _DBType
57 | End Get
58 | Set(ByVal Value As Integer)
59 | _DBType = Value
60 | End Set
61 | End Property
62 |
63 | Public Property DBDay() As Integer
64 | Get
65 | Return _DBDay
66 | End Get
67 | Set(ByVal Value As Integer)
68 | _DBDay = Value
69 | End Set
70 | End Property
71 |
72 | Public Property DBMonth() As Integer
73 | Get
74 | Return _DBMonth
75 | End Get
76 | Set(ByVal Value As Integer)
77 | _DBMonth = Value
78 | End Set
79 | End Property
80 |
81 | Public Property DBYear() As Integer
82 | Get
83 | Return _DBYear
84 | End Get
85 | Set(ByVal Value As Integer)
86 | _DBYear = Value
87 | End Set
88 | End Property
89 |
90 | Public Property BaseAddrIPv6() As Integer
91 | Get
92 | Return _BaseAddrIPv6
93 | End Get
94 | Set(ByVal Value As Integer)
95 | _BaseAddrIPv6 = Value
96 | End Set
97 | End Property
98 |
99 | Public Property DBCountIPv6() As Integer
100 | Get
101 | Return _DBCountIPv6
102 | End Get
103 | Set(ByVal Value As Integer)
104 | _DBCountIPv6 = Value
105 | End Set
106 | End Property
107 |
108 | Public Property OldBIN() As Boolean
109 | Get
110 | Return _OldBIN
111 | End Get
112 | Set(ByVal Value As Boolean)
113 | _OldBIN = Value
114 | End Set
115 | End Property
116 |
117 | Public Property Indexed() As Boolean
118 | Get
119 | Return _Indexed
120 | End Get
121 | Set(ByVal Value As Boolean)
122 | _Indexed = Value
123 | End Set
124 | End Property
125 |
126 | Public Property IndexedIPv6() As Boolean
127 | Get
128 | Return _IndexedIPv6
129 | End Get
130 | Set(ByVal Value As Boolean)
131 | _IndexedIPv6 = Value
132 | End Set
133 | End Property
134 |
135 | Public Property IndexBaseAddr() As Integer
136 | Get
137 | Return _IndexBaseAddr
138 | End Get
139 | Set(ByVal Value As Integer)
140 | _IndexBaseAddr = Value
141 | End Set
142 | End Property
143 |
144 | Public Property IndexBaseAddrIPv6() As Integer
145 | Get
146 | Return _IndexBaseAddrIPv6
147 | End Get
148 | Set(ByVal Value As Integer)
149 | _IndexBaseAddrIPv6 = Value
150 | End Set
151 | End Property
152 |
153 | Public Property ProductCode() As Integer
154 | Get
155 | Return _ProductCode
156 | End Get
157 | Set(ByVal Value As Integer)
158 | _ProductCode = Value
159 | End Set
160 | End Property
161 |
162 | Public Property ProductType() As Integer
163 | Get
164 | Return _ProductType
165 | End Get
166 | Set(ByVal Value As Integer)
167 | _ProductType = Value
168 | End Set
169 | End Property
170 |
171 | Public Property FileSize() As Integer
172 | Get
173 | Return _FileSize
174 | End Get
175 | Set(ByVal Value As Integer)
176 | _FileSize = Value
177 | End Set
178 | End Property
179 | End Class
180 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/My Project/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/IP2LocationHTTPModule.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 |
7 |
8 |
9 |
10 | {2825F3C9-6057-488F-8353-CE9C417CA5FE}
11 | Library
12 | IP2Location
13 | IP2LocationHTTPModule
14 | 512
15 | Windows
16 | v3.5
17 |
18 |
19 |
20 | true
21 | full
22 | true
23 | true
24 | bin\Debug\
25 | IP2LocationHTTPModule.xml
26 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
27 |
28 |
29 | pdbonly
30 | false
31 | true
32 | true
33 | bin\Release\
34 | IP2LocationHTTPModule.xml
35 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
36 |
37 |
38 | On
39 |
40 |
41 | Binary
42 |
43 |
44 | Off
45 |
46 |
47 | On
48 |
49 |
50 | true
51 |
52 |
53 | IP2LocationHTTPModule.snk
54 |
55 |
56 |
57 | ..\packages\IntX.1.0.1.0\lib\net20\IntXLib.dll
58 | True
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | True
87 | Application.myapp
88 |
89 |
90 | True
91 | True
92 | Resources.resx
93 |
94 |
95 | True
96 | Settings.settings
97 | True
98 |
99 |
100 |
101 |
102 |
103 | VbMyResourcesResXFileCodeGenerator
104 | Resources.Designer.vb
105 | My.Resources
106 | Designer
107 |
108 |
109 |
110 |
111 |
112 | MyApplicationCodeGenerator
113 | Application.Designer.vb
114 |
115 |
116 | SettingsSingleFileGenerator
117 | My
118 | Settings.Designer.vb
119 |
120 |
121 |
122 |
123 |
124 | "C:\Program Files (x86)\Microsoft\ILMerge\ilmerge" /out:"$(ProjectDir)merged\IP2LocationHTTPModule.dll" /keyfile:"$(ProjectDir)IP2LocationHTTPModule.snk" "$(TargetDir)IP2LocationHTTPModule.dll" "$(TargetDir)IntXLib.dll"
125 |
126 |
133 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/LookupClass.vb:
--------------------------------------------------------------------------------
1 | '---------------------------------------------------------------------------
2 | ' Author : IP2Location.com
3 | ' URL : http://www.ip2location.com
4 | ' Email : sales@ip2location.com
5 | '
6 | ' Copyright (c) 2002-2025 IP2Location.com
7 | '---------------------------------------------------------------------------
8 | Public Class IPResult
9 | Dim m_ip As String = "?"
10 | Dim m_ipno As String = "?"
11 | Dim m_countrySHORT As String = "?"
12 | Dim m_countryLONG As String = "?"
13 | Dim m_region As String = "?"
14 | Dim m_city As String = "?"
15 | Dim m_latitude As Single
16 | Dim m_longitude As Single
17 | Dim m_zipcode As String = "?"
18 | Dim m_isp As String = "?"
19 | Dim m_domain As String = "?"
20 | Dim m_timezone As String = "?"
21 | Dim m_netspeed As String = "?"
22 | Dim m_iddcode As String = "?"
23 | Dim m_areacode As String = "?"
24 | Dim m_weatherstationcode As String = "?"
25 | Dim m_weatherstationname As String = "?"
26 | Dim m_mcc As String = "?"
27 | Dim m_mnc As String = "?"
28 | Dim m_mobilebrand As String = "?"
29 | Dim m_elevation As Single
30 | Dim m_usagetype As String = "?"
31 | Dim m_addresstype As String = "?"
32 | Dim m_category As String = "?"
33 | Dim m_district As String = "?"
34 | Dim m_asn As String = "?"
35 | Dim m_as As String = "?"
36 | Dim m_as_domain As String = "?"
37 | Dim m_as_usagetype As String = "?"
38 | Dim m_as_cidr As String = "?"
39 | Dim m_status As String = "?"
40 |
41 | ' Description: Get/Set the value of IPAddress
42 | Public Property IPAddress() As String
43 | Get
44 | Return m_ip
45 | End Get
46 | Set(ByVal Value As String)
47 | m_ip = Value
48 | End Set
49 | End Property
50 |
51 | ' Description: Get/Set the value of IPNumber
52 | Public Property IPNumber() As String
53 | Get
54 | Return m_ipno
55 | End Get
56 | Set(ByVal Value As String)
57 | m_ipno = Value
58 | End Set
59 | End Property
60 |
61 | ' Description: Get/Set the value of CountryShort
62 | Public Property CountryShort() As String
63 | Get
64 | Return m_countrySHORT
65 | End Get
66 | Set(ByVal Value As String)
67 | m_countrySHORT = Value
68 | End Set
69 | End Property
70 |
71 | ' Description: Get/Set the value of CountryLong
72 | Public Property CountryLong() As String
73 | Get
74 | Return m_countryLONG
75 | End Get
76 | Set(ByVal Value As String)
77 | m_countryLONG = Value
78 | End Set
79 | End Property
80 |
81 | ' Description: Get/Set the value of Region
82 | Public Property Region() As String
83 | Get
84 | Return m_region
85 | End Get
86 | Set(ByVal Value As String)
87 | m_region = Value
88 | End Set
89 | End Property
90 |
91 | ' Description: Get/Set the value of City
92 | Public Property City() As String
93 | Get
94 | Return m_city
95 | End Get
96 | Set(ByVal Value As String)
97 | m_city = Value
98 | End Set
99 | End Property
100 |
101 | ' Description: Get/Set the value of Latitude
102 | Public Property Latitude() As Single
103 | Get
104 | Return m_latitude
105 | End Get
106 | Set(ByVal Value As Single)
107 | m_latitude = Value
108 | End Set
109 | End Property
110 |
111 | ' Description: Get/Set the value of Longitude
112 | Public Property Longitude() As Single
113 | Get
114 | Return m_longitude
115 | End Get
116 | Set(ByVal Value As Single)
117 | m_longitude = Value
118 | End Set
119 | End Property
120 |
121 | ' Description: Get/Set the value of ZIPCode
122 | Public Property ZipCode() As String
123 | Get
124 | Return m_zipcode
125 | End Get
126 | Set(ByVal Value As String)
127 | m_zipcode = Value
128 | End Set
129 | End Property
130 |
131 | ' Description: Get/Set the value of TimeZone
132 | Public Property TimeZone() As String
133 | Get
134 | Return m_timezone
135 | End Get
136 | Set(ByVal Value As String)
137 | m_timezone = Value
138 | End Set
139 | End Property
140 |
141 | ' Description: Get/Set the value of NetSpeed
142 | Public Property NetSpeed() As String
143 | Get
144 | Return m_netspeed
145 | End Get
146 | Set(ByVal Value As String)
147 | m_netspeed = Value
148 | End Set
149 | End Property
150 |
151 | ' Description: Get/Set the value of IDDCode
152 | Public Property IDDCode() As String
153 | Get
154 | Return m_iddcode
155 | End Get
156 | Set(ByVal Value As String)
157 | m_iddcode = Value
158 | End Set
159 | End Property
160 |
161 | ' Description: Get/Set the value of AreaCode
162 | Public Property AreaCode() As String
163 | Get
164 | Return m_areacode
165 | End Get
166 | Set(ByVal Value As String)
167 | m_areacode = Value
168 | End Set
169 | End Property
170 |
171 | ' Description: Get/Set the value of WeatherStationCode
172 | Public Property WeatherStationCode() As String
173 | Get
174 | Return m_weatherstationcode
175 | End Get
176 | Set(ByVal Value As String)
177 | m_weatherstationcode = Value
178 | End Set
179 | End Property
180 |
181 | ' Description: Get/Set the value of WeatherStationName
182 | Public Property WeatherStationName() As String
183 | Get
184 | Return m_weatherstationname
185 | End Get
186 | Set(ByVal Value As String)
187 | m_weatherstationname = Value
188 | End Set
189 | End Property
190 |
191 | ' Description: Get/Set the value of InternetServiceProvider
192 | Public Property InternetServiceProvider() As String
193 | Get
194 | Return m_isp
195 | End Get
196 | Set(ByVal Value As String)
197 | m_isp = Value
198 | End Set
199 | End Property
200 |
201 | ' Description: Get/Set the value of DomainName
202 | Public Property DomainName() As String
203 | Get
204 | Return m_domain
205 | End Get
206 | Set(ByVal Value As String)
207 | m_domain = Value
208 | End Set
209 | End Property
210 |
211 | ' Description: Get/Set the value of MCC
212 | Public Property MCC() As String
213 | Get
214 | Return m_mcc
215 | End Get
216 | Set(ByVal Value As String)
217 | m_mcc = Value
218 | End Set
219 | End Property
220 |
221 | ' Description: Get/Set the value of MNC
222 | Public Property MNC() As String
223 | Get
224 | Return m_mnc
225 | End Get
226 | Set(ByVal Value As String)
227 | m_mnc = Value
228 | End Set
229 | End Property
230 |
231 | ' Description: Get/Set the value of MobileBrand
232 | Public Property MobileBrand() As String
233 | Get
234 | Return m_mobilebrand
235 | End Get
236 | Set(ByVal Value As String)
237 | m_mobilebrand = Value
238 | End Set
239 | End Property
240 |
241 | ' Description: Get/Set the value of Elevation
242 | Public Property Elevation() As Single
243 | Get
244 | Return m_elevation
245 | End Get
246 | Set(ByVal Value As Single)
247 | m_elevation = Value
248 | End Set
249 | End Property
250 |
251 | ' Description: Get/Set the value of UsageType
252 | Public Property UsageType() As String
253 | Get
254 | Return m_usagetype
255 | End Get
256 | Set(ByVal Value As String)
257 | m_usagetype = Value
258 | End Set
259 | End Property
260 |
261 | ' Description: Get/Set the value of AddressType
262 | Public Property AddressType() As String
263 | Get
264 | Return m_addresstype
265 | End Get
266 | Set(ByVal Value As String)
267 | m_addresstype = Value
268 | End Set
269 | End Property
270 |
271 | ' Description: Get/Set the value of Category
272 | Public Property Category() As String
273 | Get
274 | Return m_category
275 | End Get
276 | Set(ByVal Value As String)
277 | m_category = Value
278 | End Set
279 | End Property
280 |
281 | ' Description: Get/Set the value of District
282 | Public Property District() As String
283 | Get
284 | Return m_district
285 | End Get
286 | Set(ByVal Value As String)
287 | m_district = Value
288 | End Set
289 | End Property
290 |
291 | ' Description: Get/Set the value of ASN
292 | Public Property ASN() As String
293 | Get
294 | Return m_asn
295 | End Get
296 | Set(ByVal Value As String)
297 | m_asn = Value
298 | End Set
299 | End Property
300 |
301 | ' Description: Get/Set the value of AS
302 | Public Property [AS]() As String
303 | Get
304 | Return m_as
305 | End Get
306 | Set(ByVal Value As String)
307 | m_as = Value
308 | End Set
309 | End Property
310 |
311 | ' Description: Get/Set the value of AS domain
312 | Public Property ASDomain() As String
313 | Get
314 | Return m_as_domain
315 | End Get
316 | Set(ByVal Value As String)
317 | m_as_domain = Value
318 | End Set
319 | End Property
320 |
321 | ' Description: Get/Set the value of AS usage type
322 | Public Property ASUsageType() As String
323 | Get
324 | Return m_as_usagetype
325 | End Get
326 | Set(ByVal Value As String)
327 | m_as_usagetype = Value
328 | End Set
329 | End Property
330 |
331 | ' Description: Get/Set the value of AS CIDR
332 | Public Property ASCIDR() As String
333 | Get
334 | Return m_as_cidr
335 | End Get
336 | Set(ByVal Value As String)
337 | m_as_cidr = Value
338 | End Set
339 | End Property
340 |
341 | ' Description: Get/Set the value of Status
342 | Public Property Status() As String
343 | Get
344 | Return m_status
345 | End Get
346 | Set(ByVal Value As String)
347 | m_status = Value
348 | End Set
349 | End Property
350 | End Class
351 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/IP2LocationHTTPModule.vb:
--------------------------------------------------------------------------------
1 | '--------------------------------------------------------------------------
2 | ' Title : IP2Location HTTP Module
3 | ' Description : This module lookup the IP2Location database from an IP address and does redirections as well as insert server variables.
4 | ' Requirements : .NET 3.5 Framework (due to IIS limitations, .NET 3.5 module is the easiest to deploy)
5 | ' IIS Versions : 7.0, 7.5, 8.0 & 8.5
6 | '
7 | ' Author : IP2Location.com
8 | ' URL : http://www.ip2location.com
9 | ' Email : sales@ip2location.com
10 | '
11 | ' Copyright (c) 2002-2025 IP2Location.com
12 | '
13 | '---------------------------------------------------------------------------
14 |
15 | Imports System.IO
16 | Imports System.Text.RegularExpressions
17 | Imports System.Web
18 | Imports System.Xml.Serialization
19 |
20 | Public Class HTTPModule : Implements IHttpModule
21 | Public oIP2Location As IP2Location = Nothing
22 | Public oIPResult As IPResult = Nothing
23 | Private oConfig As IP2LocationConfig = Nothing
24 | Private Const configFile As String = "IP2Location-config.xml"
25 | Private globalConfig As String = Nothing
26 | Private baseDir As String = ""
27 | Public whitespace As Regex
28 | Private ReadOnly version As String = "8.8" 'follow all the paid components versioning
29 |
30 | Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
31 | LogDebug.WriteLog("Exiting IP2Location HTTP Module")
32 | oIP2Location = Nothing
33 | oIPResult = Nothing
34 | oConfig = Nothing
35 | End Sub
36 |
37 | Public Sub Init(context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
38 | oIP2Location = New IP2Location
39 | oIPResult = New IPResult
40 | Dim mydirectory As String = ""
41 |
42 | globalConfig = Environment.GetEnvironmentVariable("IP2LocationHTTPModuleConfig")
43 | If globalConfig IsNot Nothing Then 'server level mode
44 | LogDebug.WriteLog("Global config: " & globalConfig)
45 | mydirectory = globalConfig
46 | If Not mydirectory.EndsWith("\") Then
47 | mydirectory &= "\"
48 | End If
49 | Else 'website level mode
50 | baseDir = AppDomain.CurrentDomain.BaseDirectory
51 | mydirectory = baseDir & "bin\" 'always assume config file in bin folder
52 | End If
53 |
54 | Try
55 | LogDebug.WriteLog("Starting IP2Location HTTP Module " & version)
56 | whitespace = New Regex("\s")
57 |
58 | oConfig = ReadConfig(mydirectory & configFile)
59 |
60 | 'Set BIN file path
61 | If globalConfig IsNot Nothing Then
62 | oIP2Location.IPDatabasePath = oConfig.Settings.BINFile 'global BIN is always full path
63 | Else
64 | oIP2Location.IPDatabasePath = baseDir & oConfig.Settings.BINFile 'website BIN is always relative to website root folder
65 | End If
66 |
67 | AddHandler context.PreRequestHandlerExecute, AddressOf OnPreExecuteRequestHandler
68 | Catch ex As Exception
69 | LogDebug.WriteLog(ex.Message & vbNewLine & ex.StackTrace)
70 | End Try
71 | End Sub
72 |
73 | Public Sub OnPreExecuteRequestHandler(sender As Object, e As EventArgs)
74 | Dim app As HttpApplication = DirectCast(sender, HttpApplication)
75 | Dim request As HttpRequest = app.Context.Request
76 | Dim response As HttpResponse = app.Context.Response
77 | Dim myrule As BlockRule
78 | Dim myrule2 As RedirectRule
79 | Dim myIP As String
80 | Dim myurl As String
81 | Dim bypass As Boolean = False
82 | Dim bypassip As ByPassIP
83 | ' PRODUCTION ONE
84 | If oConfig.Settings.CustomIPServerVariable.Trim <> "" Then
85 | myIP = request.ServerVariables.Item(oConfig.Settings.CustomIPServerVariable.Trim)
86 | Else
87 | myIP = request.UserHostAddress
88 | End If
89 |
90 | Try
91 | ' Try the safe version first
92 | myurl = request.Url.AbsoluteUri
93 | Catch ex As UriFormatException
94 | Dim rawHost As String = request.ServerVariables("HTTP_HOST")
95 | Dim rawUrl As String = request.RawUrl
96 | Dim scheme As String = If(request.IsSecureConnection, "https", "http")
97 |
98 | ' Build manually, even if invalid
99 | myurl = $"{scheme}://{rawHost}{rawUrl}"
100 | LogDebug.WriteLog("Invalid URI encountered. Raw URL: " & myurl)
101 | Exit Sub
102 | End Try
103 |
104 | ' output extra info so we know it is working
105 | LogDebug.WriteLog("Querying IP: " & myIP)
106 | oIPResult = oIP2Location.IPQuery(myIP)
107 | LogDebug.WriteLog("Query Status: " & oIPResult.Status)
108 | LogDebug.WriteLog("Full URL: " & myurl)
109 |
110 | If oIPResult.Status = "OK" OrElse oIPResult.Status = "NOT_REGISTERED" Then
111 | If oConfig.ByPassIPs IsNot Nothing Then
112 | For Each bypassip In oConfig.ByPassIPs
113 | If bypassip.IP = myIP Then
114 | bypass = True
115 | Exit For
116 | End If
117 | Next
118 | End If
119 |
120 | If Not bypass Then
121 | 'blocking rules has priority over redirect rules
122 | If oConfig.BlockRules IsNot Nothing Then
123 | For Each myrule In oConfig.BlockRules
124 | If myrule.Enabled Then
125 | myrule.Comparison = myrule.Comparison.ToUpper.Trim
126 | myrule.Countries = whitespace.Replace(myrule.Countries.ToUpper, String.Empty) 'String.Empty is apparently faster than normal blank string
127 | myrule.FromURL = myrule.FromURL.Trim
128 |
129 | If myrule.Comparison = "IN" Then
130 | If myrule.Countries.Split(",").Contains(oIPResult.CountryShort) Then
131 | If Regex.IsMatch(myurl, myrule.FromURL, RegexOptions.IgnoreCase) Then
132 | app.CompleteRequest()
133 | app.Response.StatusCode = 403
134 | End If
135 | End If
136 | ElseIf myrule.Comparison = "NOT IN" Then
137 | If Not myrule.Countries.Split(",").Contains(oIPResult.CountryShort) Then
138 | If Regex.IsMatch(myurl, myrule.FromURL, RegexOptions.IgnoreCase) Then
139 | app.CompleteRequest()
140 | app.Response.StatusCode = 403
141 | End If
142 | End If
143 | End If
144 | End If
145 | Next
146 | End If
147 |
148 | 'if above no blocking rules matched, then we can process redirect rules
149 | If oConfig.RedirectRules IsNot Nothing Then
150 | For Each myrule2 In oConfig.RedirectRules
151 | If myrule2.Enabled Then
152 | myrule2.Comparison = myrule2.Comparison.ToUpper.Trim
153 | myrule2.Countries = whitespace.Replace(myrule2.Countries.ToUpper, String.Empty) 'String.Empty is apparently faster than normal blank string
154 | myrule2.FromURL = myrule2.FromURL.Trim
155 | myrule2.ToURL = myrule2.ToURL.Trim
156 |
157 | If myrule2.Comparison = "IN" Then
158 | If myrule2.Countries.Split(",").Contains(oIPResult.CountryShort) Then
159 | If Regex.IsMatch(myurl, myrule2.FromURL, RegexOptions.IgnoreCase) Then
160 | response.Redirect(myrule2.ToURL, True)
161 | End If
162 | End If
163 | ElseIf myrule2.Comparison = "NOT IN" Then
164 | If Not myrule2.Countries.Split(",").Contains(oIPResult.CountryShort) Then
165 | If Regex.IsMatch(myurl, myrule2.FromURL, RegexOptions.IgnoreCase) Then
166 | response.Redirect(myrule2.ToURL, True)
167 | End If
168 | End If
169 | End If
170 | End If
171 | Next
172 | End If
173 | Else
174 | LogDebug.WriteLog("ByPassing IP: " & myIP)
175 | End If
176 |
177 | If oConfig.Settings.EnabledServerVariable Then
178 | request.ServerVariables.Item("HTTP_X_COUNTRY_SHORT") = oIPResult.CountryShort
179 | request.ServerVariables.Item("HTTP_X_COUNTRY_LONG") = oIPResult.CountryLong
180 | request.ServerVariables.Item("HTTP_X_COUNTRY_REGION") = oIPResult.Region
181 | request.ServerVariables.Item("HTTP_X_COUNTRY_CITY") = oIPResult.City
182 | request.ServerVariables.Item("HTTP_X_COUNTRY_ISP") = oIPResult.InternetServiceProvider
183 | request.ServerVariables.Item("HTTP_X_COUNTRY_LATITUDE") = oIPResult.Latitude
184 | request.ServerVariables.Item("HTTP_X_COUNTRY_LONGITUDE") = oIPResult.Longitude
185 | request.ServerVariables.Item("HTTP_X_COUNTRY_DOMAIN") = oIPResult.DomainName
186 | request.ServerVariables.Item("HTTP_X_COUNTRY_ZIPCODE") = oIPResult.ZipCode
187 | request.ServerVariables.Item("HTTP_X_COUNTRY_TIMEZONE") = oIPResult.TimeZone
188 | request.ServerVariables.Item("HTTP_X_COUNTRY_NETSPEED") = oIPResult.NetSpeed
189 | request.ServerVariables.Item("HTTP_X_COUNTRY_IDD_CODE") = oIPResult.IDDCode
190 | request.ServerVariables.Item("HTTP_X_COUNTRY_AREA_CODE") = oIPResult.AreaCode
191 | request.ServerVariables.Item("HTTP_X_COUNTRY_WEATHER_CODE") = oIPResult.WeatherStationCode
192 | request.ServerVariables.Item("HTTP_X_COUNTRY_WEATHER_NAME") = oIPResult.WeatherStationName
193 | request.ServerVariables.Item("HTTP_X_COUNTRY_MCC") = oIPResult.MCC
194 | request.ServerVariables.Item("HTTP_X_COUNTRY_MNC") = oIPResult.MNC
195 | request.ServerVariables.Item("HTTP_X_COUNTRY_MOBILE_BRAND") = oIPResult.MobileBrand
196 | request.ServerVariables.Item("HTTP_X_COUNTRY_ELEVATION") = oIPResult.Elevation
197 | request.ServerVariables.Item("HTTP_X_COUNTRY_USAGE_TYPE") = oIPResult.UsageType
198 | request.ServerVariables.Item("HTTP_X_COUNTRY_ADDRESS_TYPE") = oIPResult.AddressType
199 | request.ServerVariables.Item("HTTP_X_COUNTRY_CATEGORY") = oIPResult.Category
200 | request.ServerVariables.Item("HTTP_X_COUNTRY_DISTRICT") = oIPResult.District
201 | request.ServerVariables.Item("HTTP_X_COUNTRY_ASN") = oIPResult.ASN
202 | request.ServerVariables.Item("HTTP_X_COUNTRY_AS") = oIPResult.AS
203 | request.ServerVariables.Item("HTTP_X_COUNTRY_AS_DOMAIN") = oIPResult.ASDomain
204 | request.ServerVariables.Item("HTTP_X_COUNTRY_AS_USAGE_TYPE") = oIPResult.ASUsageType
205 | request.ServerVariables.Item("HTTP_X_COUNTRY_AS_CIDR") = oIPResult.ASCIDR
206 | End If
207 | End If
208 | End Sub
209 |
210 | Private Function ReadConfig(ByVal filename As String) As IP2LocationConfig
211 | ' Create an instance of the XmlSerializer class;
212 | ' specify the type of object to be deserialized.
213 | Dim serializer As New XmlSerializer(GetType(IP2LocationConfig))
214 | ' If the XML document has been altered with unknown
215 | ' nodes or attributes, handle them with the
216 | ' UnknownNode and UnknownAttribute events.
217 | AddHandler serializer.UnknownNode, AddressOf SerializerUnknownNode
218 | AddHandler serializer.UnknownAttribute, AddressOf SerializerUnknownAttribute
219 |
220 | ' All these just to make sure XML is following our case sensitivity.
221 | Dim line As String
222 | Dim sr2 As StringReader = Nothing
223 | Dim regexstr As New List(Of String)
224 | Dim normalelem As String
225 | normalelem = "Settings|BIN_File|License_Key|Company_Name|Enabled_Server_Variables|ByPassIPs|ByPassIP|IP|BlockRules|BlockRule|URL_Regex|Comparison|Countries|Enabled_Rule|RedirectRules|RedirectRule|Redirect_To_URL"
226 | Dim elem As String
227 | Dim elem2 As String
228 |
229 | regexstr.Add("(?)(IP2Location_Configuration)([>|\s])") 'main element
230 |
231 | For Each elem In normalelem.Split("|")
232 | regexstr.Add("(?)(" & elem & ")(>)")
233 | Next
234 |
235 | Try
236 | 'Have to make sure all the XML supplied by user is correct case
237 | Using sr As New StreamReader(filename)
238 | line = sr.ReadToEnd()
239 | End Using
240 |
241 | 'Fix the XML here using replace
242 | For Each elem In regexstr
243 | elem2 = elem.Replace(")(", "#").Split("#")(1) 'to get the tag name with specific case sensitivity
244 | line = Regex.Replace(line, elem, "$1" & elem2 & "$3", RegexOptions.IgnoreCase)
245 | Next
246 |
247 | ' Declare an object variable of the type to be deserialized.
248 | Dim config As IP2LocationConfig
249 | ' Use the Deserialize method to restore the object's state with
250 | ' data from the XML document.
251 |
252 | sr2 = New StringReader(line)
253 |
254 | config = CType(serializer.Deserialize(sr2), IP2LocationConfig)
255 |
256 | Return config
257 | Catch ex As Exception
258 | LogDebug.WriteLog(ex.Message)
259 | Throw 'special case so need to throw here to stop the main process
260 | Finally
261 | If sr2 IsNot Nothing Then
262 | sr2.Close()
263 | End If
264 | End Try
265 | End Function
266 |
267 | Private Sub SerializerUnknownNode(sender As Object, e As XmlNodeEventArgs)
268 | LogDebug.WriteLog("Unknown Node:" & e.Name & vbTab & e.Text)
269 | End Sub
270 |
271 | Private Sub SerializerUnknownAttribute(sender As Object, e As XmlAttributeEventArgs)
272 | Dim attr As System.Xml.XmlAttribute = e.Attr
273 | LogDebug.WriteLog("Unknown attribute " & attr.Name & "='" & attr.Value & "'")
274 | End Sub
275 |
276 | End Class
277 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IP2Location IP Geolocation HTTP Module
2 |
3 | This IIS managed module allows user to get geolocation information about an IP address such as country of origin, region, city, latitude, longitude, ZIP code, ISP, domain name, time zone, connection speed, IDD code, area code, weather station code, and weather station name, mobile country code (MCC), mobile network code (MNC), carrier brand, usage type, elevation, address type, IAB category, district, autonomous system number (ASN) and autonomous system (AS). It lookup the IP address from **IP2Location BIN Data** file. This data file can be downloaded at
4 |
5 | * Free IP2Location IP geolocation BIN Data: https://lite.ip2location.com
6 | * Commercial IP2Location IP geolocation BIN Data: https://www.ip2location.com/database/ip2location
7 |
8 |
9 | ## Requirements
10 |
11 | * Visual Studio 2010 or later.
12 | * Microsoft .NET 3.5 framework.
13 | * [IntX](https://www.nuget.org/packages/IntX/)
14 | * [Microsoft ILMerge](https://www.microsoft.com/en-my/download/details.aspx?id=17630)
15 |
16 | Supported Microsoft IIS Versions: 7.0, 7.5, 8.0, 8.5, 10.0 (website needs to be running under a .NET 2.0 application pool in integrated mode)
17 |
18 |
19 | ## Compilation
20 |
21 | Just open the solution file in Visual Studio and compile. Or just use the IP2LocationHTTPModule.dll in the dll folder.
22 |
23 | **NOTE: After compilation, the final IP2LocationHTTPModule.dll will be in the merged folder as the post-build event will merge the IntXLib.dll with the original IP2LocationHTTPModule.dll to make it easier for deployment.**
24 |
25 | ___
26 |
27 | ## Installation & Configuration
28 |
29 | **NOTE: You can choose to install the IP2Location IP Geolocation HTTP Module in either per website mode or per server mode.**
30 |
31 | If you install in per website mode, you will need to install and configure for every website that you wish to add the IP2Location feature.
32 | If you install in per server mode, you just need to install and configure once and all websites hosted on that machine will be able to use IP2Location.
33 |
34 | ### Installation & Configuration (per website mode)
35 |
36 | 1. Copy the IP2LocationHTTPModule.dll, IP2Location-config.xml and the BIN data file to the bin folder of your website.
37 |
38 | 2. Modify your web.config as below:
39 |
40 | ```xml
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | ```
50 |
51 | 3. Open the IP2Location-config.xml file in your bin folder using any text editor and you can see the below:
52 |
53 | ```xml
54 |
55 |
56 |
57 | bin\your_database_file.BIN
58 |
59 |
60 | HTTP_X_FORWARDED_FOR
61 | True
62 |
63 |
64 |
65 | 1.2.3.4
66 |
67 |
68 |
69 |
70 | .*\.php
71 | NOT IN
72 | US,CA,MY
73 | True
74 |
75 |
76 |
77 |
78 | .*/Default\.aspx
79 | http://www.google.sg
80 | IN
81 | MY,SG,AU
82 | True
83 |
84 |
85 |
86 | ```
87 |
88 | What should I change? (ByPassIPs, BlockRules & RedirectRules are optional if you do not require them)
89 |
90 | - <BIN_File>The relative path for the BIN database file that you have copied into the bin folder of your website. (relative to the root of your website)
91 | - <Company_Name>No longer required, just leave this blank
92 | - <License_Key>No longer required, just leave this blank
93 | - <Custom_IP_Server_Variable>Leave blank unless you need to read the IP from a custom field.
94 | - <Enabled_Server_Variables>When the value is True, your webpages can have access to IP Geolocation data for your visitor’s IP address via server variables. You can turn this off by changing the value to False.
95 | - Under <ByPassIPs>, each <ByPassIP>is used to configure an IP address to bypass the block/redirect rules. Just add another <ByPassIP> segment if you want to have another IP address bypass the rules.
96 | - Under <BlockRules>, each <BlockRule>is used to configure a rule for blocking visitor access to the website. Just add another <BlockRule> segment if you want another rule.
97 | - <URL_Regex>A regular expression string to match various pages and sub-folders.
98 | - <Comparison>Allows 2 values; either IN or NOT IN. In the case of IN, if the visitor’s country is in the <Countries> list for that rule and the <URL_Regex> matches the browsed URL then the visitor will be blocked via a HTTP 403 status.
99 | - <Enabled_Rule>Accepts either True or False and this just turns on or off the rule.
100 | - <RedirectRules> and <RedirectRule> works similar to the <BlockRules>, except the visitor is redirected to the URL specified in <Redirect_To_URL> instead of being blocked.
101 |
102 |
103 | ### Installation & Configuration (per server mode)
104 |
105 | 1. Create a new folder.
106 |
107 | 2. Copy the IP2LocationHTTPModule.dll, IP2Location-config.xml and the BIN data file to that folder.
108 |
109 | 3. Create a Windows environment system variable to store the path of the new folder.
110 | 1. Open the Control Panel then double-click on System then click on Advanced System Settings.
111 | 2. Click on the Environment Variables button to open up the Environment Variable settings.
112 | 3. Under System variables, create a new variable called IP2LocationHTTPModuleConfig and set the value to the full path of the new folder.
113 |
114 | 4. Create a PowerShell script called installgac.ps1 and paste the following code into it.
115 |
116 | ```powershell
117 | Set-location "C:\"
118 | [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
119 | $publish = New-Object System.EnterpriseServices.Internal.Publish
120 | $publish.GacInstall("C:\\IP2LocationHTTPModule.dll")
121 | iisreset
122 | ```
123 |
124 | 5. Create a PowerShell script called uninstallgac.ps1 and paste the following code into it.
125 |
126 | ```powershell
127 | Set-location "C:\"
128 | [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
129 | $publish = New-Object System.EnterpriseServices.Internal.Publish
130 | $publish.GacRemove("C:\\IP2LocationHTTPModule.dll")
131 | iisreset
132 | ```
133 |
134 | 6. In both scripts, edit the 2 lines containing the path to the full path for your new folder then save the scripts.
135 |
136 | 7. Run installgac.ps1 to install the dll into the GAC. Keep the uninstallgac.ps1 in case you need to uninstall the dll.
137 |
138 | 8. Installing the module in IIS.
139 | 1. Open the IIS Manager then navigate to the server level settings and double-click on the Modules icon.
140 | 2. In the Modules settings, click on the Add Managed Module at the right-hand side.
141 | 3. Key in IP2LocationHTTPModule for the Name and select IP2Location.HTTPModule as the Type.
142 | 4. Click OK then restart IIS to complete the installation.
143 |
144 | 9. Open the IP2Location-config.xml in your new folder using any text editor. Fill in the <BIN_File> tag with the absolute path to your BIN data file and remove the HTTP_X_FORWARDED_FOR if your website is not behind a proxy. Save your changes.
145 |
146 | ```xml
147 |
148 |
149 |
150 | C:\\
151 |
152 |
153 | HTTP_X_FORWARDED_FOR
154 | True
155 |
156 |
157 | ```
158 |
159 | ___
160 |
161 | ## Usage
162 |
163 | Below are the server variables set by the IP2Location HTTP Module. You can use any programming languages to read the server variables.
164 |
165 | |Variable Name|Description|
166 | |---|---|
167 | |HTTP_X_COUNTRY_SHORT|Two-character country code based on ISO 3166.|
168 | |HTTP_X_COUNTRY_LONG|Country name based on ISO 3166.|
169 | |HTTP_X_COUNTRY_REGION|Region or state name.|
170 | |HTTP_X_COUNTRY_CITY|City name.|
171 | |HTTP_X_COUNTRY_LATITUDE|City latitude.|
172 | |HTTP_X_COUNTRY_LONGITUDE|City longitude.|
173 | |HTTP_X_COUNTRY_ZIPCODE|ZIP or Postal Code.|
174 | |HTTP_X_COUNTRY_TIMEZONE|UTC time zone.|
175 | |HTTP_X_COUNTRY_ISP|Internet Service Provider or company's name.|
176 | |HTTP_X_COUNTRY_DOMAIN|Internet domain name associated to IP address range.|
177 | |HTTP_X_COUNTRY_NETSPEED|Internet connection type. DIAL = dial up, DSL = broadband/cable, COMP = company/T1|
178 | |HTTP_X_COUNTRY_IDD_CODE|The IDD prefix to call the city from another country.|
179 | |HTTP_X_COUNTRY_AREA_CODE|A varying length number assigned to geographic areas for call between cities.|
180 | |HTTP_X_COUNTRY_WEATHER_CODE|The special code to identify the nearest weather observation station.|
181 | |HTTP_X_COUNTRY_WEATHER_NAME|The name of the nearest weather observation station.|
182 | |HTTP_X_COUNTRY_MCC|Mobile Country Codes (MCC) as defined in ITU E.212 for use in identifying mobile stations in wireless telephone networks, particularly GSM and UMTS networks.|
183 | |HTTP_X_COUNTRY_MNC|Mobile Network Code (MNC) is used in combination with a Mobile Country Code (MCC) to uniquely identify a mobile phone operator or carrier.|
184 | |HTTP_X_COUNTRY_MOBILE_BRAND|Commercial brand associated with the mobile carrier.|
185 | |HTTP_X_COUNTRY_ELEVATION|Average height of city above sea water in meters (m).|
186 | |HTTP_X_COUNTRY_USAGE_TYPE|Usage type classification of ISP or company:- (COM) Commercial
- (ORG) Organization
- (GOV) Government
- (MIL) Military
- (EDU) University/College/School
- (LIB) Library
- (CDN) Content Delivery Network
- (ISP) Fixed Line ISP
- (MOB) Mobile ISP
- (DCH) Data Center/Web Hosting/Transit
- (SES) Search Engine Spider
- (RSV) Reserved
|
187 | |HTTP_X_COUNTRY_ADDRESS_TYPE|IP address types as defined in Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6).- (A) Anycast - One to the closest
- (U) Unicast - One to one
- (M) Multicast - One to multiple
- (B) Broadcast - One to all
|
188 | |HTTP_X_COUNTRY_CATEGORY|The domain category is based on [IAB Tech Lab Content Taxonomy](https://www.ip2location.com/free/iab-categories). These categories are comprised of Tier-1 and Tier-2 (if available) level categories widely used in services like advertising, Internet security and filtering appliances.|
189 | |HTTP_X_COUNTRY_DISTRICT|District.|
190 | |HTTP_X_COUNTRY_ASN|Autonomous System Number.|
191 | |HTTP_X_COUNTRY_AS|Autonomous System.|
192 | |HTTP_X_COUNTRY_AS_DOMAIN|Autonomous System domain name.|
193 | |HTTP_X_COUNTRY_AS_USAGE_TYPE|Autonomous System usage type.|
194 | |HTTP_X_COUNTRY_AS_CIDR|Autonomous System CIDR.|
195 | ___
196 |
197 | ## Sample Codes
198 |
199 | ### ASP.NET (VB)
200 |
201 | ```vb.net
202 | Private Sub ShowServerVariable()
203 | Response.Write(Request.ServerVariables("REMOTE_ADDR") & "
")
204 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_SHORT") & "
")
205 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_LONG") & "
")
206 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_REGION") & "
")
207 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_CITY") & "
")
208 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_LATITUDE") & "
")
209 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_LONGITUDE") & "
")
210 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_ZIPCODE") & "
")
211 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_TIMEZONE") & "
")
212 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_ISP") & "
")
213 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_DOMAIN") & "
")
214 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_NETSPEED") & "
")
215 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_IDD_CODE") & "
")
216 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_AREA_CODE") & "
")
217 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_WEATHER_CODE") & "
")
218 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_WEATHER_NAME") & "
")
219 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_MCC") & "
")
220 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_MNC") & "
")
221 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_MOBILE_BRAND") & "
")
222 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_ELEVATION") & "
")
223 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_USAGE_TYPE") & "
")
224 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_ADDRESS_TYPE") & "
")
225 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_CATEGORY") & "
")
226 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_DISTRICT") & "
")
227 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_ASN") & "
")
228 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_AS") & "
")
229 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_AS_DOMAIN") & "
")
230 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_AS_USAGE_TYPE") & "
")
231 | Response.Write(Request.ServerVariables("HTTP_X_COUNTRY_AS_CIDR") & "
")
232 | End Sub
233 | ```
234 |
235 | ### ASP.NET (C#)
236 |
237 | ```csharp
238 | private void ShowServerVariable()
239 | {
240 | Response.Write(Request.ServerVariables["REMOTE_ADDR"] + "\n");
241 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_SHORT"] + "\n");
242 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_LONG"] + "\n");
243 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_REGION"] + "\n");
244 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_CITY"] + "\n");
245 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_LATITUDE"] + "\n");
246 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_LONGITUDE"] + "\n");
247 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_ZIPCODE"] + "\n");
248 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_TIMEZONE"] + "\n");
249 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_ISP"] + "\n");
250 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_DOMAIN"] + "\n");
251 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_NETSPEED"] + "\n");
252 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_IDD_CODE"] + "\n");
253 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_AREA_CODE"] + "\n");
254 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_WEATHER_CODE"] + "\n");
255 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_WEATHER_NAME"] + "\n");
256 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_MCC"] + "\n");
257 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_MNC"] + "\n");
258 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_MOBILE_BRAND"] + "\n");
259 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_ELEVATION"] + "\n");
260 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_USAGE_TYPE"] + "\n");
261 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_ADDRESS_TYPE"] + "\n");
262 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_CATEGORY"] + "\n");
263 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_DISTRICT"] + "\n");
264 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_ASN"] + "\n");
265 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_AS"] + "\n");
266 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_AS_DOMAIN"] + "\n");
267 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_AS_USAGE_TYPE"] + "\n");
268 | Response.Write(Request.ServerVariables["HTTP_X_COUNTRY_AS_CIDR"] + "\n");
269 | }
270 | ```
271 |
272 | ### ASP
273 |
274 | ```asp
275 |
276 |
277 | IP2Location HTTP Module
278 |
279 |
280 | <%=Request.ServerVariables("REMOTE_ADDR") & "
"%>
281 | <%=Request.ServerVariables("HTTP_X_COUNTRY_SHORT") & "
"%>
282 | <%=Request.ServerVariables("HTTP_X_COUNTRY_LONG") & "
"%>
283 | <%=Request.ServerVariables("HTTP_X_COUNTRY_REGION") & "
"%>
284 | <%=Request.ServerVariables("HTTP_X_COUNTRY_CITY") & "
"%>
285 | <%=Request.ServerVariables("HTTP_X_COUNTRY_LATITUDE") & "
"%>
286 | <%=Request.ServerVariables("HTTP_X_COUNTRY_LONGITUDE") & "
"%>
287 | <%=Request.ServerVariables("HTTP_X_COUNTRY_ZIPCODE") & "
"%>
288 | <%=Request.ServerVariables("HTTP_X_COUNTRY_TIMEZONE") & "
"%>
289 | <%=Request.ServerVariables("HTTP_X_COUNTRY_ISP") & "
"%>
290 | <%=Request.ServerVariables("HTTP_X_COUNTRY_DOMAIN") & "
"%>
291 | <%=Request.ServerVariables("HTTP_X_COUNTRY_NETSPEED") & "
"%>
292 | <%=Request.ServerVariables("HTTP_X_COUNTRY_IDD_CODE") & "
"%>
293 | <%=Request.ServerVariables("HTTP_X_COUNTRY_AREA_CODE") & "
"%>
294 | <%=Request.ServerVariables("HTTP_X_COUNTRY_WEATHER_CODE") & "
"%>
295 | <%=Request.ServerVariables("HTTP_X_COUNTRY_WEATHER_NAME") & "
"%>
296 | <%=Request.ServerVariables("HTTP_X_COUNTRY_MCC") & "
"%>
297 | <%=Request.ServerVariables("HTTP_X_COUNTRY_MNC") & "
"%>
298 | <%=Request.ServerVariables("HTTP_X_COUNTRY_MOBILE_BRAND") & "
"%>
299 | <%=Request.ServerVariables("HTTP_X_COUNTRY_ELEVATION") & "
"%>
300 | <%=Request.ServerVariables("HTTP_X_COUNTRY_USAGE_TYPE") & "
"%>
301 | <%=Request.ServerVariables("HTTP_X_COUNTRY_ADDRESS_TYPE") & "
"%>
302 | <%=Request.ServerVariables("HTTP_X_COUNTRY_CATEGORY") & "
"%>
303 | <%=Request.ServerVariables("HTTP_X_COUNTRY_DISTRICT") & "
"%>
304 | <%=Request.ServerVariables("HTTP_X_COUNTRY_ASN") & "
"%>
305 | <%=Request.ServerVariables("HTTP_X_COUNTRY_AS") & "
"%>
306 | <%=Request.ServerVariables("HTTP_X_COUNTRY_AS_DOMAIN") & "
"%>
307 | <%=Request.ServerVariables("HTTP_X_COUNTRY_AS_USAGE_TYPE") & "
"%>
308 | <%=Request.ServerVariables("HTTP_X_COUNTRY_AS_CIDR") & "
"%>
309 |
310 |
311 | ```
312 |
313 | ### PHP
314 |
315 | ```php
316 |
317 |
318 | IP2Location HTTP Module
319 |
320 |
321 | ";
323 | echo $_SERVER['HTTP_X_COUNTRY_SHORT'] . "
";
324 | echo $_SERVER['HTTP_X_COUNTRY_LONG'] . "
";
325 | echo $_SERVER['HTTP_X_COUNTRY_REGION'] . "
";
326 | echo $_SERVER['HTTP_X_COUNTRY_CITY'] . "
";
327 | echo $_SERVER['HTTP_X_COUNTRY_LATITUDE'] . "
";
328 | echo $_SERVER['HTTP_X_COUNTRY_LONGITUDE'] . "
";
329 | echo $_SERVER['HTTP_X_COUNTRY_ZIPCODE'] . "
";
330 | echo $_SERVER['HTTP_X_COUNTRY_TIMEZONE'] . "
";
331 | echo $_SERVER['HTTP_X_COUNTRY_ISP'] . "
";
332 | echo $_SERVER['HTTP_X_COUNTRY_DOMAIN'] . "
";
333 | echo $_SERVER['HTTP_X_COUNTRY_NETSPEED'] . "
";
334 | echo $_SERVER['HTTP_X_COUNTRY_IDD_CODE'] . "
";
335 | echo $_SERVER['HTTP_X_COUNTRY_AREA_CODE'] . "
";
336 | echo $_SERVER['HTTP_X_COUNTRY_WEATHER_CODE'] . "
";
337 | echo $_SERVER['HTTP_X_COUNTRY_WEATHER_NAME'] . "
";
338 | echo $_SERVER['HTTP_X_COUNTRY_MCC'] . "
";
339 | echo $_SERVER['HTTP_X_COUNTRY_MNC'] . "
";
340 | echo $_SERVER['HTTP_X_COUNTRY_MOBILE_BRAND'] . "
";
341 | echo $_SERVER['HTTP_X_COUNTRY_ELEVATION'] . "
";
342 | echo $_SERVER['HTTP_X_COUNTRY_USAGE_TYPE'] . "
";
343 | echo $_SERVER['HTTP_X_COUNTRY_ADDRESS_TYPE'] . "
";
344 | echo $_SERVER['HTTP_X_COUNTRY_CATEGORY'] . "
";
345 | echo $_SERVER['HTTP_X_COUNTRY_DISTRICT'] . "
";
346 | echo $_SERVER['HTTP_X_COUNTRY_ASN'] . "
";
347 | echo $_SERVER['HTTP_X_COUNTRY_AS'] . "
";
348 | echo $_SERVER['HTTP_X_COUNTRY_AS_DOMAIN'] . "
";
349 | echo $_SERVER['HTTP_X_COUNTRY_AS_USAGE_TYPE'] . "
";
350 | echo $_SERVER['HTTP_X_COUNTRY_AS_CIDR'] . "
";
351 | ?>
352 |
353 |
354 | ```
355 |
--------------------------------------------------------------------------------
/IP2LocationHTTPModule/IP2LocationHTTPModule/IP2Location.vb:
--------------------------------------------------------------------------------
1 | '---------------------------------------------------------------------------
2 | ' Author : IP2Location.com
3 | ' URL : http://www.ip2location.com
4 | ' Email : sales@ip2location.com
5 | '
6 | ' Copyright (c) 2002-2025 IP2Location.com
7 | '
8 | ' NOTE: Due IIS 7/7.5/8.0/8.5 being able to easily use .NET 3.5 managed module, this component also has been modified to use .NET 3.5
9 | ' and for IPv6 calculations we use IntXLib since .NET 3.5 does not come with BigInteger class.
10 | '---------------------------------------------------------------------------
11 | Imports System.IO
12 | Imports System.Net
13 | Imports System.Text
14 | Imports System.Text.RegularExpressions
15 | Imports IntXLib ' installed via NuGet
16 |
17 | Public NotInheritable Class IP2Location
18 | Private _DBFilePath As String = ""
19 | Private _MetaData As MetaData = Nothing
20 | Private ReadOnly _OutlierCase1 As New Regex("^:(:[\dA-F]{1,4}){7}$", RegexOptions.IgnoreCase)
21 | Private ReadOnly _OutlierCase2 As New Regex("^:(:[\dA-F]{1,4}){5}:(\d{1,3}\.){3}\d{1,3}$", RegexOptions.IgnoreCase)
22 | Private ReadOnly _OutlierCase3 As New Regex("^\d+$")
23 | Private ReadOnly _OutlierCase4 As New Regex("^([\dA-F]{1,4}:){6}(0\d+\.|.*?\.0\d+).*$")
24 | Private ReadOnly _IPv4MappedRegex As New Regex("^(.*:)((\d+\.){3}\d+)$")
25 | Private ReadOnly _IPv4MappedRegex2 As New Regex("^.*((:[\dA-F]{1,4}){2})$")
26 | Private ReadOnly _IPv4CompatibleRegex As New Regex("^::[\dA-F]{1,4}$", RegexOptions.IgnoreCase)
27 | Private _IPv4ColumnSize As Integer = 0
28 | Private _IPv6ColumnSize As Integer = 0
29 | Private ReadOnly _IndexArrayIPv4(65535, 1) As Integer
30 | Private ReadOnly _IndexArrayIPv6(65535, 1) As Integer
31 |
32 | Private ReadOnly _fromBI As New IntX("281470681743360")
33 | Private ReadOnly _toBI As New IntX("281474976710655")
34 | Private ReadOnly _FromBI2 As New IntX("42545680458834377588178886921629466624")
35 | Private ReadOnly _ToBI2 As New IntX("42550872755692912415807417417958686719")
36 | Private ReadOnly _FromBI3 As New IntX("42540488161975842760550356425300246528")
37 | Private ReadOnly _ToBI3 As New IntX("42540488241204005274814694018844196863")
38 | Private ReadOnly _DivBI As New IntX("4294967295")
39 |
40 | Private Const FIVESEGMENTS As String = "0000:0000:0000:0000:0000:"
41 | Private ReadOnly SHIFT64BIT As New IntX("18446744073709551616")
42 | Private ReadOnly MAX_IPV4_RANGE As New IntX("4294967295")
43 | Private ReadOnly MAX_IPV6_RANGE As New IntX("340282366920938463463374607431768211455")
44 | Private Const MSG_OK As String = "OK"
45 | Private Const MSG_INVALID_BIN As String = "Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file."
46 | Private Const MSG_NOT_SUPPORTED As String = "This method is not applicable for current IP2Location binary data file. Please upgrade your subscription package to install new data file."
47 | Private Const MSG_EVALUATION As String = "EVALUATION"
48 | Private Const MSG_NOT_REGISTERED As String = "NOT_REGISTERED"
49 |
50 | Private ReadOnly COUNTRY_POSITION() As Byte = {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}
51 | Private ReadOnly REGION_POSITION() As Byte = {0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
52 | Private ReadOnly CITY_POSITION() As Byte = {0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}
53 | Private ReadOnly ISP_POSITION() As Byte = {0, 0, 3, 0, 5, 0, 7, 5, 7, 0, 8, 0, 9, 0, 9, 0, 9, 0, 9, 7, 9, 0, 9, 7, 9, 9, 9}
54 | Private ReadOnly LATITUDE_POSITION() As Byte = {0, 0, 0, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}
55 | Private ReadOnly LONGITUDE_POSITION() As Byte = {0, 0, 0, 0, 0, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}
56 | Private ReadOnly DOMAIN_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 6, 8, 0, 9, 0, 10, 0, 10, 0, 10, 0, 10, 8, 10, 0, 10, 8, 10, 10, 10}
57 | Private ReadOnly ZIPCODE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 7, 7, 7, 0, 7, 0, 7, 7, 7, 0, 7, 7, 7}
58 | Private ReadOnly TIMEZONE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 7, 8, 8, 8, 7, 8, 0, 8, 8, 8, 0, 8, 8, 8}
59 | Private ReadOnly NETSPEED_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 11, 0, 11, 8, 11, 0, 11, 0, 11, 0, 11, 11, 11}
60 | Private ReadOnly IDDCODE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 12, 0, 12, 0, 12, 9, 12, 0, 12, 12, 12}
61 | Private ReadOnly AREACODE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 13, 0, 13, 0, 13, 10, 13, 0, 13, 13, 13}
62 | Private ReadOnly WEATHERSTATIONCODE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 14, 0, 14, 0, 14, 0, 14, 14, 14}
63 | Private ReadOnly WEATHERSTATIONNAME_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 15, 0, 15, 0, 15, 0, 15, 15, 15}
64 | Private ReadOnly MCC_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 16, 0, 16, 9, 16, 16, 16}
65 | Private ReadOnly MNC_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 17, 0, 17, 10, 17, 17, 17}
66 | Private ReadOnly MOBILEBRAND_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 18, 0, 18, 11, 18, 18, 18}
67 | Private ReadOnly ELEVATION_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 19, 0, 19, 19, 19}
68 | Private ReadOnly USAGETYPE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 20, 20, 20}
69 | Private ReadOnly ADDRESSTYPE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 21}
70 | Private ReadOnly CATEGORY_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 22}
71 | Private ReadOnly DISTRICT_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23}
72 | Private ReadOnly ASN_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24}
73 | Private ReadOnly AS_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25}
74 | Private ReadOnly ASDOMAIN_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26}
75 | Private ReadOnly ASUSAGETYPE_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27}
76 | Private ReadOnly ASCIDR_POSITION() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28}
77 |
78 | Private COUNTRY_POSITION_OFFSET As Integer = 0
79 | Private REGION_POSITION_OFFSET As Integer = 0
80 | Private CITY_POSITION_OFFSET As Integer = 0
81 | Private ISP_POSITION_OFFSET As Integer = 0
82 | Private DOMAIN_POSITION_OFFSET As Integer = 0
83 | Private ZIPCODE_POSITION_OFFSET As Integer = 0
84 | Private LATITUDE_POSITION_OFFSET As Integer = 0
85 | Private LONGITUDE_POSITION_OFFSET As Integer = 0
86 | Private TIMEZONE_POSITION_OFFSET As Integer = 0
87 | Private NETSPEED_POSITION_OFFSET As Integer = 0
88 | Private IDDCODE_POSITION_OFFSET As Integer = 0
89 | Private AREACODE_POSITION_OFFSET As Integer = 0
90 | Private WEATHERSTATIONCODE_POSITION_OFFSET As Integer = 0
91 | Private WEATHERSTATIONNAME_POSITION_OFFSET As Integer = 0
92 | Private MCC_POSITION_OFFSET As Integer = 0
93 | Private MNC_POSITION_OFFSET As Integer = 0
94 | Private MOBILEBRAND_POSITION_OFFSET As Integer = 0
95 | Private ELEVATION_POSITION_OFFSET As Integer = 0
96 | Private USAGETYPE_POSITION_OFFSET As Integer = 0
97 | Private ADDRESSTYPE_POSITION_OFFSET As Integer = 0
98 | Private CATEGORY_POSITION_OFFSET As Integer = 0
99 | Private DISTRICT_POSITION_OFFSET As Integer = 0
100 | Private ASN_POSITION_OFFSET As Integer = 0
101 | Private AS_POSITION_OFFSET As Integer = 0
102 | Private ASDOMAIN_POSITION_OFFSET As Integer = 0
103 | Private ASUSAGETYPE_POSITION_OFFSET As Integer = 0
104 | Private ASCIDR_POSITION_OFFSET As Integer = 0
105 |
106 | Private COUNTRY_ENABLED As Boolean = False
107 | Private REGION_ENABLED As Boolean = False
108 | Private CITY_ENABLED As Boolean = False
109 | Private ISP_ENABLED As Boolean = False
110 | Private DOMAIN_ENABLED As Boolean = False
111 | Private ZIPCODE_ENABLED As Boolean = False
112 | Private LATITUDE_ENABLED As Boolean = False
113 | Private LONGITUDE_ENABLED As Boolean = False
114 | Private TIMEZONE_ENABLED As Boolean = False
115 | Private NETSPEED_ENABLED As Boolean = False
116 | Private IDDCODE_ENABLED As Boolean = False
117 | Private AREACODE_ENABLED As Boolean = False
118 | Private WEATHERSTATIONCODE_ENABLED As Boolean = False
119 | Private WEATHERSTATIONNAME_ENABLED As Boolean = False
120 | Private MCC_ENABLED As Boolean = False
121 | Private MNC_ENABLED As Boolean = False
122 | Private MOBILEBRAND_ENABLED As Boolean = False
123 | Private ELEVATION_ENABLED As Boolean = False
124 | Private USAGETYPE_ENABLED As Boolean = False
125 | Private ADDRESSTYPE_ENABLED As Boolean = False
126 | Private CATEGORY_ENABLED As Boolean = False
127 | Private DISTRICT_ENABLED As Boolean = False
128 | Private ASN_ENABLED As Boolean = False
129 | Private AS_ENABLED As Boolean = False
130 | Private ASDOMAIN_ENABLED As Boolean = False
131 | Private ASUSAGETYPE_ENABLED As Boolean = False
132 | Private ASCIDR_ENABLED As Boolean = False
133 |
134 | ' Description: Set/Get the value of IPv4 database path
135 | Public Property IPDatabasePath() As String
136 | Get
137 | Return _DBFilePath
138 | End Get
139 | Set(ByVal Value As String)
140 | _DBFilePath = Value
141 | End Set
142 | End Property
143 |
144 | ' Description: Make sure the component is registered (DEPRECATED)
145 | Public Function IsRegistered() As Boolean
146 | Return True
147 | End Function
148 |
149 | ' Description: Read BIN file
150 | Private Function LoadBIN() As Boolean
151 | Dim loadOK As Boolean = False
152 | Try
153 | If _DBFilePath <> "" Then
154 | Using myFileStream As New FileStream(_DBFilePath, FileMode.Open, FileAccess.Read)
155 | Dim len = 64 ' 64-byte header
156 | Dim row(len - 1) As Byte
157 |
158 | myFileStream.Seek(0, SeekOrigin.Begin)
159 | myFileStream.Read(row, 0, len)
160 |
161 | _MetaData = New MetaData
162 | With _MetaData
163 | .DBType = Read8FromHeader(row, 0)
164 | .DBColumn = Read8FromHeader(row, 1)
165 | .DBYear = Read8FromHeader(row, 2)
166 | .DBMonth = Read8FromHeader(row, 3)
167 | .DBDay = Read8FromHeader(row, 4)
168 | .DBCount = Read32FromHeader(row, 5) '4 bytes
169 | .BaseAddr = Read32FromHeader(row, 9) '4 bytes
170 | .DBCountIPv6 = Read32FromHeader(row, 13) '4 bytes
171 | .BaseAddrIPv6 = Read32FromHeader(row, 17) '4 bytes
172 | .IndexBaseAddr = Read32FromHeader(row, 21) '4 bytes
173 | .IndexBaseAddrIPv6 = Read32FromHeader(row, 25) '4 bytes
174 | .ProductCode = Read8FromHeader(row, 29)
175 | ' below 2 fields just read for now, not being used yet
176 | .ProductType = Read8FromHeader(row, 30)
177 | .FileSize = Read32FromHeader(row, 31) '4 bytes
178 |
179 | ' check if is correct BIN (should be 1 for IP2Location BIN file), also checking for zipped file (PK being the first 2 chars)
180 | If (.ProductCode <> 1 AndAlso .DBYear >= 21) OrElse (.DBType = 80 AndAlso .DBColumn = 75) Then ' only BINs from Jan 2021 onwards have this byte set
181 | Throw New Exception(MSG_INVALID_BIN)
182 | End If
183 |
184 | If .IndexBaseAddr > 0 Then
185 | .Indexed = True
186 | End If
187 |
188 | If .DBCountIPv6 = 0 Then ' old style IPv4-only BIN file
189 | .OldBIN = True
190 | Else
191 | If .IndexBaseAddrIPv6 > 0 Then
192 | .IndexedIPv6 = True
193 | End If
194 | End If
195 |
196 | _IPv4ColumnSize = .DBColumn << 2 ' 4 bytes each column
197 | _IPv6ColumnSize = 16 + ((.DBColumn - 1) << 2) ' 4 bytes each column, except IPFrom column which is 16 bytes
198 |
199 | Dim dbt As Integer = .DBType
200 |
201 | COUNTRY_POSITION_OFFSET = If(COUNTRY_POSITION(dbt) <> 0, (COUNTRY_POSITION(dbt) - 2) << 2, 0)
202 | REGION_POSITION_OFFSET = If(REGION_POSITION(dbt) <> 0, (REGION_POSITION(dbt) - 2) << 2, 0)
203 | CITY_POSITION_OFFSET = If(CITY_POSITION(dbt) <> 0, (CITY_POSITION(dbt) - 2) << 2, 0)
204 | ISP_POSITION_OFFSET = If(ISP_POSITION(dbt) <> 0, (ISP_POSITION(dbt) - 2) << 2, 0)
205 | DOMAIN_POSITION_OFFSET = If(DOMAIN_POSITION(dbt) <> 0, (DOMAIN_POSITION(dbt) - 2) << 2, 0)
206 | ZIPCODE_POSITION_OFFSET = If(ZIPCODE_POSITION(dbt) <> 0, (ZIPCODE_POSITION(dbt) - 2) << 2, 0)
207 | LATITUDE_POSITION_OFFSET = If(LATITUDE_POSITION(dbt) <> 0, (LATITUDE_POSITION(dbt) - 2) << 2, 0)
208 | LONGITUDE_POSITION_OFFSET = If(LONGITUDE_POSITION(dbt) <> 0, (LONGITUDE_POSITION(dbt) - 2) << 2, 0)
209 | TIMEZONE_POSITION_OFFSET = If(TIMEZONE_POSITION(dbt) <> 0, (TIMEZONE_POSITION(dbt) - 2) << 2, 0)
210 | NETSPEED_POSITION_OFFSET = If(NETSPEED_POSITION(dbt) <> 0, (NETSPEED_POSITION(dbt) - 2) << 2, 0)
211 | IDDCODE_POSITION_OFFSET = If(IDDCODE_POSITION(dbt) <> 0, (IDDCODE_POSITION(dbt) - 2) << 2, 0)
212 | AREACODE_POSITION_OFFSET = If(AREACODE_POSITION(dbt) <> 0, (AREACODE_POSITION(dbt) - 2) << 2, 0)
213 | WEATHERSTATIONCODE_POSITION_OFFSET = If(WEATHERSTATIONCODE_POSITION(dbt) <> 0, (WEATHERSTATIONCODE_POSITION(dbt) - 2) << 2, 0)
214 | WEATHERSTATIONNAME_POSITION_OFFSET = If(WEATHERSTATIONNAME_POSITION(dbt) <> 0, (WEATHERSTATIONNAME_POSITION(dbt) - 2) << 2, 0)
215 | MCC_POSITION_OFFSET = If(MCC_POSITION(dbt) <> 0, (MCC_POSITION(dbt) - 2) << 2, 0)
216 | MNC_POSITION_OFFSET = If(MNC_POSITION(dbt) <> 0, (MNC_POSITION(dbt) - 2) << 2, 0)
217 | MOBILEBRAND_POSITION_OFFSET = If(MOBILEBRAND_POSITION(dbt) <> 0, (MOBILEBRAND_POSITION(dbt) - 2) << 2, 0)
218 | ELEVATION_POSITION_OFFSET = If(ELEVATION_POSITION(dbt) <> 0, (ELEVATION_POSITION(dbt) - 2) << 2, 0)
219 | USAGETYPE_POSITION_OFFSET = If(USAGETYPE_POSITION(dbt) <> 0, (USAGETYPE_POSITION(dbt) - 2) << 2, 0)
220 | ADDRESSTYPE_POSITION_OFFSET = If(ADDRESSTYPE_POSITION(dbt) <> 0, (ADDRESSTYPE_POSITION(dbt) - 2) << 2, 0)
221 | CATEGORY_POSITION_OFFSET = If(CATEGORY_POSITION(dbt) <> 0, (CATEGORY_POSITION(dbt) - 2) << 2, 0)
222 | DISTRICT_POSITION_OFFSET = If(DISTRICT_POSITION(dbt) <> 0, (DISTRICT_POSITION(dbt) - 2) << 2, 0)
223 | ASN_POSITION_OFFSET = If(ASN_POSITION(dbt) <> 0, (ASN_POSITION(dbt) - 2) << 2, 0)
224 | AS_POSITION_OFFSET = If(AS_POSITION(dbt) <> 0, (AS_POSITION(dbt) - 2) << 2, 0)
225 | ASDOMAIN_POSITION_OFFSET = If(ASDOMAIN_POSITION(dbt) <> 0, (ASDOMAIN_POSITION(dbt) - 2) << 2, 0)
226 | ASUSAGETYPE_POSITION_OFFSET = If(ASUSAGETYPE_POSITION(dbt) <> 0, (ASUSAGETYPE_POSITION(dbt) - 2) << 2, 0)
227 | ASCIDR_POSITION_OFFSET = If(ASCIDR_POSITION(dbt) <> 0, (ASCIDR_POSITION(dbt) - 2) << 2, 0)
228 |
229 | COUNTRY_ENABLED = COUNTRY_POSITION(dbt) <> 0
230 | REGION_ENABLED = REGION_POSITION(dbt) <> 0
231 | CITY_ENABLED = CITY_POSITION(dbt) <> 0
232 | ISP_ENABLED = ISP_POSITION(dbt) <> 0
233 | LATITUDE_ENABLED = LATITUDE_POSITION(dbt) <> 0
234 | LONGITUDE_ENABLED = LONGITUDE_POSITION(dbt) <> 0
235 | DOMAIN_ENABLED = DOMAIN_POSITION(dbt) <> 0
236 | ZIPCODE_ENABLED = ZIPCODE_POSITION(dbt) <> 0
237 | TIMEZONE_ENABLED = TIMEZONE_POSITION(dbt) <> 0
238 | NETSPEED_ENABLED = NETSPEED_POSITION(dbt) <> 0
239 | IDDCODE_ENABLED = IDDCODE_POSITION(dbt) <> 0
240 | AREACODE_ENABLED = AREACODE_POSITION(dbt) <> 0
241 | WEATHERSTATIONCODE_ENABLED = WEATHERSTATIONCODE_POSITION(dbt) <> 0
242 | WEATHERSTATIONNAME_ENABLED = WEATHERSTATIONNAME_POSITION(dbt) <> 0
243 | MCC_ENABLED = MCC_POSITION(dbt) <> 0
244 | MNC_ENABLED = MNC_POSITION(dbt) <> 0
245 | MOBILEBRAND_ENABLED = MOBILEBRAND_POSITION(dbt) <> 0
246 | ELEVATION_ENABLED = ELEVATION_POSITION(dbt) <> 0
247 | USAGETYPE_ENABLED = USAGETYPE_POSITION(dbt) <> 0
248 | ADDRESSTYPE_ENABLED = ADDRESSTYPE_POSITION(dbt) <> 0
249 | CATEGORY_ENABLED = CATEGORY_POSITION(dbt) <> 0
250 | DISTRICT_ENABLED = DISTRICT_POSITION(dbt) <> 0
251 | ASN_ENABLED = ASN_POSITION(dbt) <> 0
252 | AS_ENABLED = AS_POSITION(dbt) <> 0
253 | ASDOMAIN_ENABLED = ASDOMAIN_POSITION(dbt) <> 0
254 | ASUSAGETYPE_ENABLED = ASUSAGETYPE_POSITION(dbt) <> 0
255 | ASCIDR_ENABLED = ASCIDR_POSITION(dbt) <> 0
256 |
257 | If .Indexed Then
258 | Dim readLen = _IndexArrayIPv4.GetLength(0)
259 | If .IndexBaseAddrIPv6 > 0 Then
260 | readLen += _IndexArrayIPv6.GetLength(0)
261 | End If
262 |
263 | readLen *= 8 ' 4 bytes for both From/To
264 | Dim indexData(readLen - 1) As Byte
265 |
266 | myFileStream.Seek(.IndexBaseAddr - 1, SeekOrigin.Begin)
267 | myFileStream.Read(indexData, 0, readLen)
268 |
269 | Dim pointer As Integer = 0
270 |
271 | ' read IPv4 index
272 | For x As Integer = _IndexArrayIPv4.GetLowerBound(0) To _IndexArrayIPv4.GetUpperBound(0)
273 | _IndexArrayIPv4(x, 0) = Read32FromHeader(indexData, pointer) '4 bytes for from row
274 | _IndexArrayIPv4(x, 1) = Read32FromHeader(indexData, pointer + 4) '4 bytes for to row
275 | pointer += 8
276 | Next
277 |
278 | If .IndexedIPv6 Then
279 | ' read IPv6 index
280 | For x As Integer = _IndexArrayIPv6.GetLowerBound(0) To _IndexArrayIPv6.GetUpperBound(0)
281 | _IndexArrayIPv6(x, 0) = Read32FromHeader(indexData, pointer) '4 bytes for from row
282 | _IndexArrayIPv6(x, 1) = Read32FromHeader(indexData, pointer + 4) '4 bytes for to row
283 | pointer += 8
284 | Next
285 | End If
286 | End If
287 |
288 | End With
289 | End Using
290 | loadOK = True
291 | End If
292 | Catch ex As Exception
293 | LogDebug.WriteLog(ex.Message)
294 | End Try
295 |
296 | Return loadOK
297 | End Function
298 |
299 | ' Description: Reverse the bytes if system is little endian
300 | Public Sub LittleEndian(ByRef byteArr() As Byte)
301 | If BitConverter.IsLittleEndian Then
302 | Dim byteList As New List(Of Byte)(byteArr)
303 | byteList.Reverse()
304 | byteArr = byteList.ToArray()
305 | End If
306 | End Sub
307 |
308 | ' Description: Query database to get location information by IP address
309 | Public Function IPQuery(ByVal myIPAddress As String) As IPResult
310 | Dim obj As New IPResult
311 | Dim strIP As String
312 | Dim myIPType As Integer = 0
313 | Dim myDBType As Integer
314 | Dim myBaseAddr As Integer = 0
315 | Dim myDBColumn As Integer
316 | Dim myFilestream As FileStream = Nothing
317 |
318 | Dim countrypos As Long
319 | Dim low As Long = 0
320 | Dim high As Long = 0
321 | Dim mid As Long
322 | Dim ipfrom As IntX
323 | Dim ipto As IntX
324 | Dim ipnum As New IntX()
325 | Dim indexaddr As Long
326 | Dim MAX_IP_RANGE As New IntX()
327 | Dim rowoffset As Long
328 | Dim rowoffset2 As Long
329 | Dim myColumnSize As Integer = 0
330 | Dim fullRow As Byte() = Nothing
331 | Dim row As Byte()
332 | Dim firstCol As Integer = 4 ' IP From is 4 bytes
333 |
334 | Try
335 | If myIPAddress = "" OrElse myIPAddress Is Nothing Then
336 | obj.Status = "EMPTY_IP_ADDRESS"
337 | Return obj
338 | End If
339 |
340 | strIP = Me.VerifyIP(myIPAddress, myIPType, ipnum)
341 | If strIP <> "Invalid IP" Then
342 | myIPAddress = strIP
343 | Else
344 | obj.Status = "INVALID_IP_ADDRESS"
345 | Return obj
346 | End If
347 |
348 | ' Read BIN if haven't done so
349 | If _MetaData Is Nothing Then
350 | If Not LoadBIN() Then ' problems reading BIN
351 | obj.Status = "MISSING_FILE"
352 | Return obj
353 | End If
354 | End If
355 |
356 | myDBType = _MetaData.DBType
357 | myDBColumn = _MetaData.DBColumn
358 |
359 | myFilestream = New FileStream(_DBFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
360 |
361 | Select Case myIPType
362 | Case 4
363 | ' IPv4
364 | MAX_IP_RANGE = MAX_IPV4_RANGE
365 | high = _MetaData.DBCount
366 | myBaseAddr = _MetaData.BaseAddr
367 | myColumnSize = _IPv4ColumnSize
368 |
369 | If _MetaData.Indexed Then
370 | indexaddr = ipnum >> 16
371 | low = _IndexArrayIPv4(indexaddr, 0)
372 | high = _IndexArrayIPv4(indexaddr, 1)
373 | End If
374 | Case 6
375 | ' IPv6
376 | firstCol = 16 ' IPv6 is 16 bytes
377 | If _MetaData.OldBIN Then ' old IPv4-only BIN don't contain IPv6 data
378 | obj.Status = "IPV6_NOT_SUPPORTED"
379 | Return obj
380 | End If
381 | MAX_IP_RANGE = MAX_IPV6_RANGE
382 | high = _MetaData.DBCountIPv6
383 | myBaseAddr = _MetaData.BaseAddrIPv6
384 | myColumnSize = _IPv6ColumnSize
385 |
386 | If _MetaData.IndexedIPv6 Then
387 | indexaddr = ipnum >> 112
388 | low = _IndexArrayIPv6(indexaddr, 0)
389 | high = _IndexArrayIPv6(indexaddr, 1)
390 | End If
391 | End Select
392 |
393 | If ipnum >= MAX_IP_RANGE Then
394 | ipnum = MAX_IP_RANGE - New IntX(1)
395 | End If
396 |
397 | While (low <= high)
398 | mid = CInt((low + high) / 2)
399 |
400 | rowoffset = myBaseAddr + (mid * myColumnSize)
401 | rowoffset2 = rowoffset + myColumnSize
402 |
403 | ' reading IP From + whole row + next IP From
404 | fullRow = ReadRow(rowoffset, myColumnSize + firstCol, myFilestream)
405 | ipfrom = Read32Or128Row(fullRow, 0, firstCol)
406 | ipto = Read32Or128Row(fullRow, myColumnSize, firstCol)
407 |
408 | If ipnum >= ipfrom AndAlso ipnum < ipto Then
409 | Dim country_short As String = MSG_NOT_SUPPORTED
410 | Dim country_long As String = MSG_NOT_SUPPORTED
411 | Dim region As String = MSG_NOT_SUPPORTED
412 | Dim city As String = MSG_NOT_SUPPORTED
413 | Dim isp As String = MSG_NOT_SUPPORTED
414 | Dim latitude As Single = 0.0
415 | Dim longitude As Single = 0.0
416 | Dim domain As String = MSG_NOT_SUPPORTED
417 | Dim zipcode As String = MSG_NOT_SUPPORTED
418 | Dim timezone As String = MSG_NOT_SUPPORTED
419 | Dim netspeed As String = MSG_NOT_SUPPORTED
420 | Dim iddcode As String = MSG_NOT_SUPPORTED
421 | Dim areacode As String = MSG_NOT_SUPPORTED
422 | Dim weatherstationcode As String = MSG_NOT_SUPPORTED
423 | Dim weatherstationname As String = MSG_NOT_SUPPORTED
424 | Dim mcc As String = MSG_NOT_SUPPORTED
425 | Dim mnc As String = MSG_NOT_SUPPORTED
426 | Dim mobilebrand As String = MSG_NOT_SUPPORTED
427 | Dim elevation As Single = 0.0
428 | Dim usagetype As String = MSG_NOT_SUPPORTED
429 | Dim addresstype As String = MSG_NOT_SUPPORTED
430 | Dim category As String = MSG_NOT_SUPPORTED
431 | Dim district As String = MSG_NOT_SUPPORTED
432 | Dim asn As String = MSG_NOT_SUPPORTED
433 | Dim [as] As String = MSG_NOT_SUPPORTED
434 | Dim asdomain As String = MSG_NOT_SUPPORTED
435 | Dim asusagetype As String = MSG_NOT_SUPPORTED
436 | Dim ascidr As String = MSG_NOT_SUPPORTED
437 |
438 | Dim rowLen = myColumnSize - firstCol
439 |
440 | ReDim row(rowLen - 1)
441 | Array.Copy(fullRow, firstCol, row, 0, rowLen) ' extract the actual row data
442 |
443 | If COUNTRY_ENABLED Then
444 | countrypos = Read32FromRow(row, COUNTRY_POSITION_OFFSET)
445 | country_short = ReadStr(countrypos, myFilestream)
446 | country_long = ReadStr(countrypos + 3, myFilestream)
447 | End If
448 | If REGION_ENABLED Then
449 | region = ReadStr(Read32FromRow(row, REGION_POSITION_OFFSET), myFilestream)
450 | End If
451 | If CITY_ENABLED Then
452 | city = ReadStr(Read32FromRow(row, CITY_POSITION_OFFSET), myFilestream)
453 | End If
454 | If ISP_ENABLED Then
455 | isp = ReadStr(Read32FromRow(row, ISP_POSITION_OFFSET), myFilestream)
456 | End If
457 | If DOMAIN_ENABLED Then
458 | domain = ReadStr(Read32FromRow(row, DOMAIN_POSITION_OFFSET), myFilestream)
459 | End If
460 | If ZIPCODE_ENABLED Then
461 | zipcode = ReadStr(Read32FromRow(row, ZIPCODE_POSITION_OFFSET), myFilestream)
462 | End If
463 | If LATITUDE_ENABLED Then
464 | latitude = ReadFloatFromRow(row, LATITUDE_POSITION_OFFSET)
465 | End If
466 | If LONGITUDE_ENABLED Then
467 | longitude = ReadFloatFromRow(row, LONGITUDE_POSITION_OFFSET)
468 | End If
469 | If TIMEZONE_ENABLED Then
470 | timezone = ReadStr(Read32FromRow(row, TIMEZONE_POSITION_OFFSET), myFilestream)
471 | End If
472 | If NETSPEED_ENABLED Then
473 | netspeed = ReadStr(Read32FromRow(row, NETSPEED_POSITION_OFFSET), myFilestream)
474 | End If
475 | If IDDCODE_ENABLED Then
476 | iddcode = ReadStr(Read32FromRow(row, IDDCODE_POSITION_OFFSET), myFilestream)
477 | End If
478 | If AREACODE_ENABLED Then
479 | areacode = ReadStr(Read32FromRow(row, AREACODE_POSITION_OFFSET), myFilestream)
480 | End If
481 | If WEATHERSTATIONCODE_ENABLED Then
482 | weatherstationcode = ReadStr(Read32FromRow(row, WEATHERSTATIONCODE_POSITION_OFFSET), myFilestream)
483 | End If
484 | If WEATHERSTATIONNAME_ENABLED Then
485 | weatherstationname = ReadStr(Read32FromRow(row, WEATHERSTATIONNAME_POSITION_OFFSET), myFilestream)
486 | End If
487 | If MCC_ENABLED Then
488 | mcc = ReadStr(Read32FromRow(row, MCC_POSITION_OFFSET), myFilestream)
489 | End If
490 | If MNC_ENABLED Then
491 | mnc = ReadStr(Read32FromRow(row, MNC_POSITION_OFFSET), myFilestream)
492 | End If
493 | If MOBILEBRAND_ENABLED Then
494 | mobilebrand = ReadStr(Read32FromRow(row, MOBILEBRAND_POSITION_OFFSET), myFilestream)
495 | End If
496 | If ELEVATION_ENABLED Then
497 | Single.TryParse(ReadStr(Read32FromRow(row, ELEVATION_POSITION_OFFSET), myFilestream), elevation)
498 | End If
499 | If USAGETYPE_ENABLED Then
500 | usagetype = ReadStr(Read32FromRow(row, USAGETYPE_POSITION_OFFSET), myFilestream)
501 | End If
502 | If ADDRESSTYPE_ENABLED Then
503 | addresstype = ReadStr(Read32FromRow(row, ADDRESSTYPE_POSITION_OFFSET), myFilestream)
504 | End If
505 | If CATEGORY_ENABLED Then
506 | category = ReadStr(Read32FromRow(row, CATEGORY_POSITION_OFFSET), myFilestream)
507 | End If
508 | If DISTRICT_ENABLED Then
509 | district = ReadStr(Read32FromRow(row, DISTRICT_POSITION_OFFSET), myFilestream)
510 | End If
511 | If ASN_ENABLED Then
512 | asn = ReadStr(Read32FromRow(row, ASN_POSITION_OFFSET), myFilestream)
513 | End If
514 | If AS_ENABLED Then
515 | [as] = ReadStr(Read32FromRow(row, AS_POSITION_OFFSET), myFilestream)
516 | End If
517 | If ASDOMAIN_ENABLED Then
518 | asdomain = ReadStr(Read32FromRow(row, ASDOMAIN_POSITION_OFFSET), myFilestream)
519 | End If
520 | If ASUSAGETYPE_ENABLED Then
521 | asusagetype = ReadStr(Read32FromRow(row, ASUSAGETYPE_POSITION_OFFSET), myFilestream)
522 | End If
523 | If ASCIDR_ENABLED Then
524 | ascidr = ReadStr(Read32FromRow(row, ASCIDR_POSITION_OFFSET), myFilestream)
525 | End If
526 |
527 | obj.IPAddress = myIPAddress
528 | obj.IPNumber = ipnum.ToString()
529 | obj.CountryShort = country_short
530 | obj.CountryLong = country_long
531 | obj.Region = region
532 | obj.City = city
533 | obj.InternetServiceProvider = isp
534 | obj.DomainName = domain
535 | obj.ZipCode = zipcode
536 | obj.NetSpeed = netspeed
537 | obj.IDDCode = iddcode
538 | obj.AreaCode = areacode
539 | obj.WeatherStationCode = weatherstationcode
540 | obj.WeatherStationName = weatherstationname
541 | obj.TimeZone = timezone
542 | obj.Latitude = latitude
543 | obj.Longitude = longitude
544 | obj.MCC = mcc
545 | obj.MNC = mnc
546 | obj.MobileBrand = mobilebrand
547 | obj.Elevation = elevation
548 | obj.UsageType = usagetype
549 | obj.AddressType = addresstype
550 | obj.Category = category
551 | obj.District = district
552 | obj.ASN = asn
553 | obj.AS = [as]
554 | obj.ASDomain = asdomain
555 | obj.ASUsageType = asusagetype
556 | obj.ASCIDR = ascidr
557 |
558 | obj.Status = MSG_OK
559 |
560 | Return obj
561 | Else
562 | If ipnum < ipfrom Then
563 | high = mid - 1
564 | Else
565 | low = mid + 1
566 | End If
567 | End If
568 | End While
569 |
570 | obj.Status = "IP_ADDRESS_NOT_FOUND"
571 | Return obj
572 | Catch ex As Exception
573 | LogDebug.WriteLog(ex.Message)
574 | obj.Status = "UNKNOWN_ERROR"
575 | Return obj
576 | Finally
577 | If myFilestream IsNot Nothing Then
578 | myFilestream.Close()
579 | myFilestream.Dispose()
580 | End If
581 | End Try
582 | End Function
583 |
584 | ' Read whole row into array of bytes
585 | Private Function ReadRow(ByVal _Pos As Long, ByVal MyLen As UInt32, ByRef MyFilestream As FileStream) As Byte()
586 | Dim row(MyLen - 1) As Byte
587 | MyFilestream.Seek(_Pos - 1, SeekOrigin.Begin)
588 | MyFilestream.Read(row, 0, MyLen)
589 | Return row
590 | End Function
591 |
592 | ' Read 8 bits in the database
593 | Private Function Read8(ByVal _Pos As Long, ByRef MyFilestream As FileStream) As Byte
594 | Try
595 | Dim _Byte(0) As Byte
596 | MyFilestream.Seek(_Pos - 1, SeekOrigin.Begin)
597 | MyFilestream.Read(_Byte, 0, 1)
598 | Return _Byte(0)
599 | Catch ex As Exception
600 | LogDebug.WriteLog("Read8-" & ex.Message)
601 | Return 0
602 | End Try
603 | End Function
604 |
605 | ' Read 8 bits in header
606 | Private Function Read8FromHeader(ByRef row() As Byte, ByVal byteOffset As Integer) As Integer
607 | Dim _Byte(0) As Byte ' 1 byte
608 | Array.Copy(row, byteOffset, _Byte, 0, 1)
609 | Return _Byte(0)
610 | End Function
611 |
612 | ' Read 32 bits in header
613 | Private Function Read32FromHeader(ByRef row() As Byte, ByVal byteOffset As Integer) As Integer
614 | Dim _Byte(3) As Byte ' 4 bytes
615 | Array.Copy(row, byteOffset, _Byte, 0, 4)
616 | Return BitConverter.ToUInt32(_Byte, 0)
617 | End Function
618 |
619 | Private Function Read32Or128Row(ByRef row() As Byte, ByVal byteOffset As Integer, ByVal len As Integer) As IntX
620 | Try
621 | Dim _Byte(len - 1) As Byte
622 | Array.Copy(row, byteOffset, _Byte, 0, len)
623 | If len = 4 Then
624 | Return New IntX(BitConverter.ToUInt32(_Byte, 0).ToString())
625 | ElseIf len = 16 Then
626 | Dim bigRetVal As IntX
627 |
628 | bigRetVal = New IntX(BitConverter.ToUInt64(_Byte, 8).ToString())
629 | bigRetVal *= SHIFT64BIT
630 | bigRetVal += New IntX(BitConverter.ToUInt64(_Byte, 0).ToString())
631 |
632 | Return bigRetVal
633 | Else
634 | Return New IntX()
635 | End If
636 | Catch ex As Exception
637 | LogDebug.WriteLog("Read32Or128Row-" & ex.Message)
638 | Return New IntX()
639 | End Try
640 | End Function
641 |
642 | Private Function Read32or128(ByVal _Pos As Long, ByVal _MyIPType As Integer, ByRef MyFilestream As FileStream) As IntX
643 | If _MyIPType = 4 Then
644 | Return Read32(_Pos, MyFilestream)
645 | ElseIf _MyIPType = 6 Then
646 | Return Read128(_Pos, MyFilestream)
647 | Else
648 | Return New IntX()
649 | End If
650 | End Function
651 |
652 | ' Read 128 bits in the database
653 | Private Function Read128(ByVal _Pos As Long, ByRef MyFilestream As FileStream) As IntX
654 | Try
655 | Dim bigRetVal As IntX
656 |
657 | Dim _Byte(15) As Byte ' 16 bytes
658 | MyFilestream.Seek(_Pos - 1, SeekOrigin.Begin)
659 | MyFilestream.Read(_Byte, 0, 16)
660 | bigRetVal = New IntX(BitConverter.ToUInt64(_Byte, 8).ToString())
661 | bigRetVal *= SHIFT64BIT
662 | bigRetVal += New IntX(BitConverter.ToUInt64(_Byte, 0).ToString())
663 |
664 | Return bigRetVal
665 | Catch ex As Exception
666 | LogDebug.WriteLog("Read128-" & ex.Message)
667 | Return New IntX()
668 | End Try
669 | End Function
670 |
671 | ' Read 32 bits in byte array
672 | Private Function Read32FromRow(ByRef row() As Byte, ByVal byteOffset As Integer) As IntX
673 | Try
674 | Dim _Byte(3) As Byte ' 4 bytes
675 | Array.Copy(row, byteOffset, _Byte, 0, 4)
676 |
677 | Return New IntX(BitConverter.ToUInt32(_Byte, 0).ToString())
678 | Catch ex As Exception
679 | LogDebug.WriteLog("Read32FromRow-" & ex.Message)
680 | Throw
681 | End Try
682 | End Function
683 |
684 | ' Read 32 bits in the database
685 | Private Function Read32(ByVal _Pos As Long, ByRef MyFilestream As FileStream) As IntX
686 | Try
687 | Dim _Byte(3) As Byte ' 4 bytes
688 | MyFilestream.Seek(_Pos - 1, SeekOrigin.Begin)
689 | MyFilestream.Read(_Byte, 0, 4)
690 |
691 | Return New IntX(BitConverter.ToUInt32(_Byte, 0).ToString())
692 | Catch ex As Exception
693 | LogDebug.WriteLog("Read32-" & ex.Message)
694 | Return New IntX()
695 | End Try
696 | End Function
697 |
698 | ' Read strings in the database
699 | Private Function ReadStr(ByVal _Pos As Long, ByRef Myfilestream As FileStream) As String
700 | Try
701 | Dim _Size = 256 ' max size of string field + 1 byte for the length
702 | Dim _Data(_Size - 1) As Byte
703 |
704 | Dim _Len As Byte
705 | Dim _Bytes() As Byte
706 | Myfilestream.Seek(_Pos, SeekOrigin.Begin)
707 | Myfilestream.Read(_Data, 0, _Size)
708 | _Len = _Data(0)
709 | ReDim _Bytes(_Len - 1)
710 | Array.Copy(_Data, 1, _Bytes, 0, _Len)
711 | Return Encoding.Default.GetString(_Bytes)
712 | Catch ex As Exception
713 | LogDebug.WriteLog("ReadStr-" & ex.Message)
714 | Return ""
715 | End Try
716 | End Function
717 |
718 | ' Read float number in byte array
719 | Private Function ReadFloatFromRow(ByRef row() As Byte, ByVal byteOffset As Integer) As Single
720 | Try
721 | Dim _Byte(3) As Byte
722 | Array.Copy(row, byteOffset, _Byte, 0, 4)
723 | Return BitConverter.ToSingle(_Byte, 0)
724 | Catch ex As Exception
725 | LogDebug.WriteLog("ReadFloatFromRow-" & ex.Message)
726 | Return 0
727 | End Try
728 | End Function
729 |
730 | ' Description: Initialize
731 | Public Sub New()
732 | End Sub
733 |
734 | ' Description: Validate the IP address input
735 | Private Function VerifyIP(ByVal strParam As String, ByRef strIPType As Integer, ByRef ipnum As IntX) As String
736 | Try
737 | Dim address As IPAddress = Nothing
738 | Dim finalIP As String = ""
739 |
740 | 'do checks for outlier cases here
741 | If _OutlierCase1.IsMatch(strParam) OrElse _OutlierCase2.IsMatch(strParam) Then 'good ip list outliers
742 | strParam = "0000" & strParam.Substring(1)
743 | End If
744 |
745 | If Not _OutlierCase3.IsMatch(strParam) AndAlso Not _OutlierCase4.IsMatch(strParam) AndAlso IPAddress.TryParse(strParam, address) Then
746 | Select Case address.AddressFamily
747 | Case Sockets.AddressFamily.InterNetwork
748 | strIPType = 4
749 | Case Sockets.AddressFamily.InterNetworkV6
750 | strIPType = 6
751 | Case Else
752 | Return "Invalid IP"
753 | End Select
754 |
755 | finalIP = address.ToString().ToUpper()
756 |
757 | ipnum = IPNo(address)
758 |
759 | If strIPType = 6 Then
760 | If ipnum >= _fromBI AndAlso ipnum <= _toBI Then
761 | 'ipv4-mapped ipv6 should treat as ipv4 and read ipv4 data section
762 | strIPType = 4
763 | ipnum -= _fromBI
764 |
765 | 'expand ipv4-mapped ipv6
766 | If _IPv4MappedRegex.IsMatch(finalIP) Then
767 | finalIP = finalIP.Replace("::", FIVESEGMENTS)
768 | ElseIf _IPv4MappedRegex2.IsMatch(finalIP) Then
769 | Dim mymatch As Match = _IPv4MappedRegex2.Match(finalIP)
770 | Dim x As Integer = 0
771 |
772 | Dim tmp As String = mymatch.Groups(1).ToString()
773 | Dim tmparr() As String = tmp.Trim(":").Split(":")
774 | Dim len As Integer = tmparr.Length - 1
775 | For x = 0 To len
776 | tmparr(x) = tmparr(x).PadLeft(4, "0")
777 | Next
778 | Dim myrear As String = String.Join("", tmparr)
779 | Dim bytes As Byte()
780 |
781 | bytes = BitConverter.GetBytes(Convert.ToInt32("0x" & myrear, 16))
782 | finalIP = finalIP.Replace(tmp, ":" & bytes(3) & "." & bytes(2) & "." & bytes(1) & "." & bytes(0))
783 | finalIP = finalIP.Replace("::", FIVESEGMENTS)
784 | End If
785 | ElseIf ipnum >= _FromBI2 AndAlso ipnum <= _ToBI2 Then
786 | '6to4 so need to remap to ipv4
787 | strIPType = 4
788 |
789 | ipnum >>= 80
790 | ipnum = ipnum And _DivBI ' get last 32 bits
791 | ElseIf ipnum >= _FromBI3 AndAlso ipnum <= _ToBI3 Then
792 | 'Teredo so need to remap to ipv4
793 | strIPType = 4
794 |
795 | ipnum = Not ipnum
796 | ipnum = ipnum And _DivBI ' get last 32 bits
797 | ElseIf ipnum <= MAX_IPV4_RANGE Then
798 | 'ipv4-compatible ipv6 (DEPRECATED BUT STILL SUPPORTED BY .NET)
799 | strIPType = 4
800 |
801 | If _IPv4CompatibleRegex.IsMatch(finalIP) Then
802 | Dim bytes As Byte() = BitConverter.GetBytes(Convert.ToInt32(finalIP.Replace("::", "0x"), 16))
803 | finalIP = "::" & bytes(3) & "." & bytes(2) & "." & bytes(1) & "." & bytes(0)
804 | ElseIf finalIP = "::" Then
805 | finalIP &= "0.0.0.0"
806 | End If
807 | finalIP = finalIP.Replace("::", FIVESEGMENTS & "FFFF:")
808 | Else
809 | 'expand ipv6 normal
810 | Dim myarr() As String = Regex.Split(finalIP, "::")
811 | Dim x As Integer = 0
812 | Dim leftside As New List(Of String)
813 | leftside.AddRange(myarr(0).Split(":"))
814 |
815 | If myarr.Length > 1 Then
816 | Dim rightside As New List(Of String)
817 | rightside.AddRange(myarr(1).Split(":"))
818 |
819 | Dim midarr As List(Of String)
820 | midarr = Enumerable.Repeat("0000", 8 - leftside.Count - rightside.Count).ToList
821 |
822 | rightside.InsertRange(0, midarr)
823 | rightside.InsertRange(0, leftside)
824 |
825 | Dim rlen As Integer = rightside.Count - 1
826 | For x = 0 To rlen
827 | rightside.Item(x) = rightside.Item(x).PadLeft(4, "0")
828 | Next
829 |
830 | finalIP = String.Join(":", rightside.ToArray())
831 | Else
832 | Dim llen As Integer = leftside.Count - 1
833 | For x = 0 To llen
834 | leftside.Item(x) = leftside.Item(x).PadLeft(4, "0")
835 | Next
836 |
837 | finalIP = String.Join(":", leftside.ToArray())
838 | End If
839 | End If
840 |
841 | End If
842 |
843 | Return finalIP
844 | Else
845 | Return "Invalid IP"
846 | End If
847 | Catch ex As Exception
848 | Return "Invalid IP"
849 | End Try
850 | End Function
851 |
852 | ' Description: Convert either IPv4 or IPv6 into big integer
853 | Private Function IPNo(ByRef ipAddress As IPAddress) As IntX
854 | Try
855 | Dim addrBytes() As Byte = ipAddress.GetAddressBytes()
856 | LittleEndian(addrBytes)
857 |
858 | Dim final As IntX
859 |
860 | If addrBytes.Length > 8 Then
861 | 'IPv6
862 | final = New IntX(BitConverter.ToUInt64(addrBytes, 8).ToString())
863 | final *= SHIFT64BIT
864 | final += New IntX(BitConverter.ToUInt64(addrBytes, 0).ToString())
865 | Else
866 | 'IPv4
867 | final = New IntX(BitConverter.ToUInt32(addrBytes, 0).ToString())
868 | End If
869 |
870 | Return final
871 | Catch ex As Exception
872 | Return New IntX()
873 | End Try
874 | End Function
875 | End Class
--------------------------------------------------------------------------------