Steps for redirecting from an IP address to a user's City

Source: Internet
Author: User

First go to the next latest pure IP database, and then perform the following operations:
1. Run showip.exe in the pure qq ip data library, click extract, and enter the file name, such as ip.txt. Then, you will get a TXT file.
2. Open ACCESS, tool-custom, command tab, and drag the import option to the toolbar above.
3. Create a database and a table with four fields
Startip type: Text (IP segment information of the relevant City)
Endip type: Text (IP address segment information of the relevant City)
Country type: Text (city name)
ReUrl type: text (the city path you want to jump to, such as: Beijing http://bj.abc.com)
4.click import button, select a file from the file list, find the ip.txt file that was just exported, and import it to the table just created ~
Converts a real IP address to a number. For example, the IP address range in Beijing is 1.1.0.0 -- 1.1.0.255.
Startip: 1*256*256*256 + 1*256*256 + 0*256 + 0 = 16842752 (This number is the final number to be put into the database)
Endip: 1*256*256*256 + 1*256*256 + 0*256 + 255 = 16843007 (This number is the final number to be placed in the database)
If you can use a program for batch processing, If You Don't Have Time (like me), you can directly go to the IP address library of the next dynamic network. It has already been processed. below is the program section:
User_ip = Request. ServerVariables ("REMOTE_ADDR") ''get the visitor's IP address
Userip_ary = split (user_ip ,".")
Tmp_userip = userip_ary (0) * 256*256*256 + userip_ary (1) * 256*256 + userip_ary (2) * 256 + userip_ary (3) ''convert the IP address to a number as required
'Identify the city where the user's IP belongs from the database
Set rs = Server. CreateObject ("ADODB. Recordset ")
SQL = "select * from ip where Startip <=" & tmp_userip & "and Endip> =" & tmp_userip
Rs. open SQL, conn, 1, 1
If rs. eof then
Response. redirect "index. asp" 'If the city is not found or the IP address cannot be identified, go to the home page. You can also specify the page
Else
Response. redirect rs ("ReUrl ")'
End if
Rs. close
Set rs = nothing
Place the above program on the default homepage of your VM! Or other pages (of course, you also need to set the default access to this file in the VM Control Panel) OK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.