欢迎来到天天文库
浏览记录
ID:37289608
大小:16.19 KB
页数:8页
时间:2019-05-20
《查询域名服务器代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.InetAddress类importjava.net.*;importjava.io.*;publicclassHostLookup{publicstaticvoidmain(Stringargs[]){if(args.length>0){for(inti=0;i2、stem.in));System.out.println("请输入主机名或IP地址,输入"exit"退出程序!");try{while(true){System.out.print("主机名或IP地址:");Stringhost=bin.readLine();//读取键盘输入if(host.equalsIgnoreCase("exit")3、4、host.equalsIgnoreCase("quit"))break;System.out.println(lookup(host));}//调用lookup方法转换输入的字符}c5、atch(IOExceptione){System.out.println(e);}}}privatestaticStringlookup(Stringhost){InetAddressaddr;try{addr=InetAddress.getByName(host);}catch(UnknownHostExceptione){return"cannotfindhost"+host;}if(isHostname(host)){System.out.print(host+"的IP地址为:");//是主机名returnaddr.6、getHostAddress();}else{System.out.print(host+"的主机名为:");//是IP地址returnaddr.getHostName();}}privatestaticbooleanisHostname(Stringhost){char[]ca=host.toCharArray();for(inti=0;i7、关代码利用URL类获取网络资源importjava.net.URL;importjava.io.BufferedReader;importjava.io.InputStreamReader;publicclassTestURL{publicStringgetContent(StringstrUrl)//返回字符串,错误则返回"erroropenurl"{try{URLurl=newURL(strUrl);BufferedReaderbr=newBufferedReader(newInputStreamReader(url.o8、penStream()));Strings="";StringBuffersb=newStringBuffer("");while((s=br.readLine())!=null){sb.append(s+"r");}br.close();returnsb.toString();}catch(Exceptione){return"erroropenurl"+strUrl;}}publicstaticvoidmain(Stringargs[]){TestURLou=newTestURL();//具体使用方法System.9、out.println(ou.getContent("http://developers.sun.com/services/index.jsp"));}}3URLConnection类一个具有IE功能的小型浏览器importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;importjava.io.*;importjava.net.*;publicclassbrowserextendsJFrame{JLabeljl10、abel;JTextFieldjtf;JEditorPaneedpl;publicbrowser(){super("browser");Containercon=getContentPane();jlabel=newJLabel("请输入要访问的网址:");jtf=newJTextFiel
2、stem.in));System.out.println("请输入主机名或IP地址,输入"exit"退出程序!");try{while(true){System.out.print("主机名或IP地址:");Stringhost=bin.readLine();//读取键盘输入if(host.equalsIgnoreCase("exit")
3、
4、host.equalsIgnoreCase("quit"))break;System.out.println(lookup(host));}//调用lookup方法转换输入的字符}c
5、atch(IOExceptione){System.out.println(e);}}}privatestaticStringlookup(Stringhost){InetAddressaddr;try{addr=InetAddress.getByName(host);}catch(UnknownHostExceptione){return"cannotfindhost"+host;}if(isHostname(host)){System.out.print(host+"的IP地址为:");//是主机名returnaddr.
6、getHostAddress();}else{System.out.print(host+"的主机名为:");//是IP地址returnaddr.getHostName();}}privatestaticbooleanisHostname(Stringhost){char[]ca=host.toCharArray();for(inti=0;i7、关代码利用URL类获取网络资源importjava.net.URL;importjava.io.BufferedReader;importjava.io.InputStreamReader;publicclassTestURL{publicStringgetContent(StringstrUrl)//返回字符串,错误则返回"erroropenurl"{try{URLurl=newURL(strUrl);BufferedReaderbr=newBufferedReader(newInputStreamReader(url.o8、penStream()));Strings="";StringBuffersb=newStringBuffer("");while((s=br.readLine())!=null){sb.append(s+"r");}br.close();returnsb.toString();}catch(Exceptione){return"erroropenurl"+strUrl;}}publicstaticvoidmain(Stringargs[]){TestURLou=newTestURL();//具体使用方法System.9、out.println(ou.getContent("http://developers.sun.com/services/index.jsp"));}}3URLConnection类一个具有IE功能的小型浏览器importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;importjava.io.*;importjava.net.*;publicclassbrowserextendsJFrame{JLabeljl10、abel;JTextFieldjtf;JEditorPaneedpl;publicbrowser(){super("browser");Containercon=getContentPane();jlabel=newJLabel("请输入要访问的网址:");jtf=newJTextFiel
7、关代码利用URL类获取网络资源importjava.net.URL;importjava.io.BufferedReader;importjava.io.InputStreamReader;publicclassTestURL{publicStringgetContent(StringstrUrl)//返回字符串,错误则返回"erroropenurl"{try{URLurl=newURL(strUrl);BufferedReaderbr=newBufferedReader(newInputStreamReader(url.o
8、penStream()));Strings="";StringBuffersb=newStringBuffer("");while((s=br.readLine())!=null){sb.append(s+"r");}br.close();returnsb.toString();}catch(Exceptione){return"erroropenurl"+strUrl;}}publicstaticvoidmain(Stringargs[]){TestURLou=newTestURL();//具体使用方法System.
9、out.println(ou.getContent("http://developers.sun.com/services/index.jsp"));}}3URLConnection类一个具有IE功能的小型浏览器importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;importjava.io.*;importjava.net.*;publicclassbrowserextendsJFrame{JLabeljl
10、abel;JTextFieldjtf;JEditorPaneedpl;publicbrowser(){super("browser");Containercon=getContentPane();jlabel=newJLabel("请输入要访问的网址:");jtf=newJTextFiel
此文档下载收益归作者所有