.htaccess阻止IP和Windows OS组合

时间:2015-05-20 13:21:26

标签: .htaccess

我不知道这是否可行,但如果他们正在运行Windows,我想阻止特定IP访问该网站。

我可以阻止.htaccess中的操作系统,我可以阻止IP。但是我该如何组合呢。

基本上,如果那个人通过MAC从该IP访问该站点,它应该通过。

2 个答案:

答案 0 :(得分:2)

尝试此代码,请更改操作系统名称和IP,您要阻止

RewriteEngine On
#found OS in user agent
RewriteCond %{HTTP_USER_AGENT} .*Windows
# any IP you want to add in condtion
RewriteCond %{REMOTE_ADDR} ^192.168.1.68$
# Access forbidden any url!
RewriteRule ^(.*)$ - [F,L]

您可以在OS字符串中找到客户http_user_agent,找到Windows的任何地方,.*也会匹配WindowsWindows ME或{{ 1}}等 其他Window X将匹配IP地址, 这两个条件将一起使用RewriteCond以禁止使用[RewriteRule]标记的任何网址,并将F标记用于立即响应。

答案 1 :(得分:1)

您可以使用HTTP User-Agent标头检测操作系统,您可以使用mod_rewrite进行匹配。请参阅此链接以获取列表:http://www.geekpedia.com/code47_Detect-operating-system-from-user-agent-string.html

您还可以使用mod_rewrite与#include <stdio.h> void addPainting(void); void erasePainting(void); void printData(void); void modifyData(void); int main() { struct paintings { char code[20]; char name[50]; char paintingName[50]; double price; int year; }painting[100]; int choice; do { printf("Menu\n"); printf("To add a painting press 1.\n"); printf("To erase a painting press 2.\n"); printf("To print data for all paintings by authors alphabetically press 3.\n"); printf ("To modify data for a painting press 4.\n"); printf("To exit the program press 5.\n"); scanf("%d",&choice); switch(choice) { case 1: { addPainting(); break; } case 2: { erasePainting(); break; } case 3: { printData(); break; } case 4: { modifyData(); break; } default: printf ("Wrong choice. Try again\n"); break; } }while (choice !=5); void addPainting() { FILE *fp; struct paintings painting; printf("Enter code:"); scanf("%s", &painting.code); printf("Enter the name of the author:"); scanf("%s", &painting.name); printf("Enter the name of the painting:"); scanf("%s", &painting.paintingName); printf("Enter price:"); scanf("%lf", &painting.price); printf("Enter the year of creation:"); scanf("%d", &painting.year); if ((fp=fopen("paintings","wb"))==NULL) exit(1); if ((fwrite (&painting,sizeof(painting),1,fp)!=1)) exit(2); fclose(fp); } } 进行匹配。如下所示:

RewriteCond

如果你有其他规则,你会希望这是第一条规则。这将检查如果用户代理包含RewriteEngine On RewriteCond %{HTTP_USER_AGENT} Windows\ [0-9A-Z] RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4$ RewriteRule ^ - [L,F] (其中X是字母数),则IP为“1.2.3.4”,则它将返回403禁止。