Gergely Szabo Mon, 07/30/2007 - 00:36

Hello,

quite easy. Look at the [HTTP] global variables of your applications.

For instance, if your services are PHP-based, then this should help:

http://sk.php.net/manual/en/reserved.variables.php#reserved.variables.server

You are looking for

$_SERVER['REMOTE_ADDR'] or

$_SERVER['REMOTE_HOST']

If ASP, then

Request.ServerVariables("remote_addr") or

Request.ServerVariables("remote_host")

zitop_tech Mon, 07/30/2007 - 00:39

thanks, it works, but in JSP, how can i get the deveicename(i can get the remoteip)?

thanks for advanced.

Gergely Szabo Mon, 07/30/2007 - 00:49

Google is your best friend ;-)

Those are standard CGI variables, must be available in PHP/ASP(X)/JSP/your-favorite.

Anyway, try this:

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.util.*;

/** Creates a table showing the values of all the CGI variables.

*

* Part of tutorial on servlets and JSP that appears at * http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/ * 1999 Marty Hall; may be freely used or adapted. */ public class ShowCGIVariables extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String[][] variables = { { "AUTH_TYPE", request.getAuthType() }, { "CONTENT_LENGTH", String.valueOf(request.getContentLength()) }, { "CONTENT_TYPE", request.getContentType() }, { "DOCUMENT_ROOT", getServletContext().getRealPath("/") }, { "PATH_INFO", request.getPathInfo() }, { "PATH_TRANSLATED", request.getPathTranslated() }, { "QUERY_STRING", request.getQueryString() }, { "REMOTE_ADDR", request.getRemoteAddr() }, { "REMOTE_HOST", request.getRemoteHost() }, { "REMOTE_USER", request.getRemoteUser() }, { "REQUEST_METHOD", request.getMethod() }, { "SCRIPT_NAME", request.getServletPath() }, { "SERVER_NAME", request.getServerName() }, { "SERVER_PORT", String.valueOf(request.getServerPort()) }, { "SERVER_PROTOCOL", request.getProtocol() }, { "SERVER_SOFTWARE", getServletContext().getServerInfo() } }; String title = "Servlet Example: Showing CGI Variables"; out.println(ServletUtilities.headWithTitle(title) + "\n" + "

" + title + "

\n" + "\n" + "\n" + "
CGI Variable NameValue"); for(int i=0; iNot specified"; out.println("
" + varName + "" + varValue); } out.println("
"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
zitop_tech Mon, 07/30/2007 - 01:37

Thanks for your advices!

maybe the "deveice Name" is not included by CGI variables.

let'me test, thanks a lot

Actions

This Discussion