Results 1 to 7 of 7
  1. #1
    madness123 is offline Member
    Join Date
    Jun 2015
    Posts
    4
    Rep Power
    0

    Default Getting destination IP and user agent

    Hi,

    I'm trying to write a Java project that extracts information from a given URL.

    Java Code:
    URL url = new URL("http://google.com");
    System.out.println(url.getHost() + " " + url.getPath() + " " + url.getQuery());
    I also need to extract the destination IP and user-agent. To my understanding, I need to create a request using URLConnection class, however I am still lost in regards of retrieving this information.

    Appreciate any advice.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Getting destination IP and user agent

    User-agent us a client detail sent to the server, you don't get them from the server itself :s

    Getting the IP of the host of an URL is an easy Google.

    http://stackoverflow.com/questions/9...rl-string-java
    Last edited by gimbal2; 07-29-2015 at 03:23 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    madness123 is offline Member
    Join Date
    Jun 2015
    Posts
    4
    Rep Power
    0

    Default Re: Getting destination IP and user agent

    Appreciate your help with the IP. Is there a way to simulate a user-agent from within the server?
    Thank you.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Getting destination IP and user agent

    Again: user-agent is a client detail, it has absolutely -nothing- to do with the server so it makes no sense to want to "simulate" it there.

    This is a typical X/Y problem. Rather than asking about solutions you pick yourself, try explaining why you need it. What unmentioned entity needs a user agent and an IP? Some unit test code perhaps?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    madness123 is offline Member
    Join Date
    Jun 2015
    Posts
    4
    Rep Power
    0

    Default Re: Getting destination IP and user agent

    Hi, I apologize for being unclear.
    What I need to do is create a system that simulates a web proxy in a system. Each user has an IP address and they supposedly visit given URLs.
    I need to log the information given by each domain (such as host, path, query etc...) one of the parameters I need to log is the User-Agent.
    I'm afraid I cannot explain the logic behind this, because I was given this task.
    I am aware that user-agent is a field sent through the browser, and that is why I seek help.

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Getting destination IP and user agent

    If you want to do more sophisticated HTTP stuff, you need more than the URL class. Go play with Apache's HttpClient. You can set the HTTP-headers there, which is what you want when you want to set User-Agent.

    Also, what gimbal says: user-agent is sent from the client to the server, not the other way around. Are you working on the client side or on the server side of this web-proxy thing?

    Edit: typo
    Last edited by SurfMan; 07-29-2015 at 04:10 PM.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  7. #7
    gozzy is offline Member
    Join Date
    Jan 2017
    Posts
    46
    Rep Power
    0

    Default Re: Getting destination IP and user agent

    This is a typical X/Y problem. Rather than asking about solutions you pick yourself, try explaining why you need it.
    Yes! IOW learn to describe your goal

Similar Threads

  1. Is it possible to set the User Agent?
    By MrFish in forum Networking
    Replies: 2
    Last Post: 07-16-2011, 06:08 PM
  2. create gui browse folder destination
    By gisler in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 04:13 PM
  3. to change the destination folder
    By raghu9198 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-23-2009, 08:45 AM
  4. Replies: 1
    Last Post: 08-08-2008, 03:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •