/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Marjorie
*/
import java.net.*;
import java.io.*;
import java.util.*;
public class eserver implements Runnable
{
Socket socket;
int id;
int count;
public static void main(String args[])
{
int count=0;
try
{
ServerSocket s= new ServerSocket(13);
while(true)
{
Socket socket=s.accept();
eserver server=new eserver(socket,count);
Thread t=new Thread(server);
t.start();
}
}
catch(Exception e)
{
System.out.println("Exception caught is::"+e);
}
}
eserver(Socket sa,int i)
{
socket=sa;
id=i;
}
public void run()
{
int flag=0;StringTokenizer t;
String id,ipAddress,str;
int i;
try{
InputStream is=socket.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);
String cls=br.readLine();
System.out.println("Client Requested : "+cls);
if(cls.trim().equals("quit"))
{
System.out.println("Client has Disconnected.....");
br.close();
}
try{
OutputStream op=socket.getOutputStream();
PrintWriter pw=new PrintWriter(op);
String clientid=cls;
String val="";
String msg="";
FileReader fr=new FileReader("iptable.txt");
BufferedReader bf=new BufferedReader(fr);
while(flag==0)
{
String b=bf.readLine();
if(b==null)
break;
t=new StringTokenizer(b);
id=t.nextToken();
ipAddress=t.nextToken();
if(id.equals(clientid))
{
System.out.println("URL :: "+id);
System.out.println("IP Address :: "+ipAddress);
val="*";flag=1;msg="URL="+id+" IP Address= "+ipAddress;
}
else
{
flag=0;msg="Sorry, Given URL is not Found.....";
}
}
bf.close();
fr.close();
if(flag==1)
pw.println(msg);
else
pw.println(msg);
pw.flush();
pw.close();
} //endtry2
catch(Exception e)
{
System.out.println("Exception caught is::"+e);
}
}//endtry1
catch(IOException e){}
//end while
}//end run
}
dns.rar_java dns
版权申诉
84 浏览量
2022-09-20
20:19:34
上传
评论
收藏 16KB RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+