AboutArtemus Harper Expertise I have a BS in computer science and am working towards a Masters degree.
Experience I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection.
knowledge of Java bytecode and annotations.
Basics in c++ and c#
Education/Credentials BS in Computer Science at Central Washington University
Question QUESTION: hello Artemus Harper..i hope u can help me..i am a new user java
programming.so lot of thing that i still cant understand. i have been develop a
monitoring system. i use a proxy function to get data that i want for
monitoring. for the proxy, i develop it by java. but for the system
interface, where will show all data captured, i use php. both of this
programming use the same database. this 2 programming doesnt have any
related. it just use the same database.java for proxy, get all data for
monitoring, and php for interface, show all data. so i dont think that will
be a problem. i dont have any problem with the php. i have done part of
the system, where i can monitor user activities. i can know the site
that user enter, the file that user download and the protocol that being
used. but i cant get the user ip address and the site ip address..here
i give u the full coding for your reference..
public class FTPMonitoring extends NetworkServer
{
public static String name;
public Socket clientsocket;
public DataOutputStream outbound1;
public BufferedReader inbound1;
public BufferedReader inbound2;
public static void main(String args[])
{
name="";
int port=1800;
try
{
port=Integer.parseInt(args[0]);
}
catch(Exception e){}
try
{
FTPMonitoring es=new FTPMonitoring();
es.startServer(port);
System.out.println("FTP monitoring start at " +new
Date().toString()+" with port "+ port);
}
catch(IOException e)
{
System.err.println("fail to start");
}
}
public void serviceRequest() throws IOException
{
String test1="",urlstring="",req,req1="";
int j=0;
query = "insert into main(url,hostname,port,filename,date,protocol)
values('"+url+"','"+ hostName+"','"+ port
+"','"+fileName+"','"+date+"','"+protocol+"')";
stmt.executeUpdate(query);
System.out.println("Data has been succesfully add to database");
}
catch(Exception e)
{
System.out.println("error add data");
}
}
public void disconnect()
{
try
{
con.close ();
System.out.println(" Connection has been disconnect");
}
catch(Exception e)
{
System.out.println("fail to disconnect");
}
}
}
i hope u can help me.. :-)"
ANSWER: The user ip address (as the one the user is connecting from) is always the same, so the Socket doesn't bother to tell you that.
To get the user's IP address you can use:
InetAddress localHost = InetAddress.getLocalHost();
you can then call toString() to get a string representation, or getAddress() to get a byte[] representation of it (the size of the byte[] depends if the computer is using IPv4 or IPv6).
To resolve a host's IP address you can use:
InetAddress siteAddress = InetAddress.getByName(hostName);
and then use one of the above techniques to get a representation of the ip address.
---------- FOLLOW-UP ----------
QUESTION: thanks you so much..i get it now..
actually i want to monitor only FTP, without bother any HTTP activites. how can my proxy bypass the HTTP activities? i mean, when user use HTTP service it will bypass the proxy, but when user use FTP service, the connection will be through by proxy. so the user who access HTTP, they will not bothered by proxy function.
ANSWER: Since this only listenes on a certian port this will not be an issue. You can sliently do nothing if an HTTP request comes though, but you are already in the proxy by the time you can realize that this is an HTTP request.
---------- FOLLOW-UP ----------
QUESTION: :-) thanks a lot..u give me an idea..now i have done some part that stuck before..thanks so much..
now i want make a filterring..the proxy will filter by sitename that has been set in database. the proxy will refer to database, if the name of site has exist in database(all site name that exist in database automatically been set to blocked by admin), then user cant access it..i really dont know how to start. so i hope u can guide me step by step.
Answer Once you got the proxy up and running, you just do a lookup into the data base when a connection to a site occurs. If the site is blocked then you redirect them to an error page (or you could just close the connection).
If you are not carefull you could greatly impact performance. Asking the data base for each request is not a good idea, at a minimum you should cache the results so multiple calls to the same website succeede without having to re ask the database. Or you could just download the entire list ahead of time. The tradeoff however is that the admin cannot make a quick change and have everyone notice that imediatly.