Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4842410
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: LINUX

2010-07-07 17:43:30

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    char *s = NULL;
    s=getenv("REMOTE_ADDR");

    printf("Content-type: text/plain;\n\n");
   
    if(s!=NULL)
     printf("ip: %s\n",s); 

    else
     printf("%s\n", "s is null");
 
   return 0;
}

 

这个是获得客户端ip的,通过getenv这个函数还可以获得以下一些东东

   "REMOTE_ADDR",
                "DOCUMENT_ROOT",
                "GATEWAY_INTERFACE",
                "SERVER_SOFTWARE",
                "SERVER_NAME",
                "SERVER_PROTOCOL",
                "SERVER_PORT",
                "SERVER_ADMIN",
                "SERVER_SIGNATURE",
                "REQUEST_METHOD",
                "REQUEST_URI",
                "PATH_INFO",
                "PATH_TRANSLATED",
                "SCRIPT_NAME",
                "SCRIPT_FILENAME",
                "QUERY_STRING",
                "REMOTE_HOST",
                "REMOTE_ADDR",
                "REMOTE_USER",
                "REMOTE_IDENT",
                "CONTENT_TYPE",
                "CONTENT_LENGTH",
                "HTTP_ACCEPT",
                "HTTP_ACCEPT_CHARSET",
                "HTTP_ACCEPT_LANGUAGE",
                "HTTP_ENCODING",
                "HTTP_USER_AGENT",
                "HTTP_CONNECTION",
                "HTTP_HOST",
                "HTTP_REFERER",
                "AUTH_TYPE"

阅读(2055) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2010-08-13 18:30:47

想请问一下。那如何尽可能多地输出这些环境变量呢?