Tuesday, 6 November 2012

Java Whois App [SOLVED]

Hello Friends I am trying to execute this code for whois application but its giving me error
please help

package network;
import java.net.*;
import java.io.*;

public class Whois {

public static void main(String[] args) throws Exception {

int c;

Socket s =new Socket("internic.net",43);
// Socket s =new Socket("localhost",8080);
// Socket s =new Socket("google.co.in",21);
try
{
InputStream in = s.getInputStream();
OutputStream out= s.getOutputStream();
String str =(args.length==0 ? "google.co.in" : args[0] )+"\n";
byte buf[] = str.getBytes();
out.write(buf);
while ((c=in.read())!=-1)
{
System.out.print((char)c);
}
s.close();
}
catch(Exception e){System.out.println(e);}

 
}

}

When I am trying to compile in command prompt and NetBeans its giving me error:

Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at network.Whois.main(Whois.java:18)


please help me with this code what is reason i am getting this error

3 comments:

  1. You are trying this app to get domain details from internic.net

    problem is that you are trying wrong address because internic.net is website which give us detail back after receiving the request. so problem is with this address change it to who.internic.net

    your application looks like this:

    package network;
    import java.net.*;
    import java.io.*;

    public class Whois {

    public static void main(String[] args) throws Exception {

    int c;

    Socket s =new Socket("who.internic.net",43);
    // Socket s =new Socket("localhost",8080);
    // Socket s =new Socket("google.co.in",21);
    try
    {
    InputStream in = s.getInputStream();
    OutputStream out= s.getOutputStream();
    String str =(args.length==0 ? "google.co.in" : args[0] )+"\n";
    byte buf[] = str.getBytes();
    out.write(buf);
    while ((c=in.read())!=-1)
    {
    System.out.print((char)c);
    }
    s.close();
    }
    catch(Exception e){System.out.println(e);}


    }

    }

    ReplyDelete
    Replies
    1. I am getting problem to execute this code and still getting error can you help me please it is urgent.
      Thank you in advance

      Delete
  2. I have made a mistake in this line and that is why problem was persist
    Please change this line

    Socket s =new Socket("who.internic.net",43);

    Change to

    Socket s =new Socket("whois.internic.net",43);

    ReplyDelete

Note: only a member of this blog may post a comment.