Advertisement
Guest User

JAVA

a guest
Oct 19th, 2018
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. Zadanie 3
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8. package javaapplication3;
  9.  
  10. import java.net.*;
  11. import java.util.Scanner;
  12.  
  13. /**
  14. *
  15. * @author student.kie
  16. */
  17. public class JavaApplication3 {
  18.  
  19. /**
  20. * @param args the command line arguments
  21. */
  22. static Scanner sc = new Scanner(System.in);
  23. public static void main(String[] args) {
  24. System.out.println("Podaj nazwę hosta");
  25. String host;
  26. host = sc.nextLine();
  27. try {
  28.  
  29. InetAddress[] addresses = InetAddress.getAllByName(host);
  30. for (int i = 0; i < addresses.length; i++) {
  31. System.out.println(addresses[i]);
  32. }
  33. }
  34. catch (UnknownHostException e) {
  35. System.out.println("Nieznany host");
  36. }
  37.  
  38. }
  39. }
  40.  
  41.  
  42.  
  43. Zadanie 2
  44.  
  45.  
  46.  
  47. /*
  48. * To change this license header, choose License Headers in Project Properties.
  49. * To change this template file, choose Tools | Templates
  50. * and open the template in the editor.
  51. */
  52. package javaapplication1;
  53.  
  54. import java.net.InetAddress;
  55. import java.net.Socket;
  56. import java.net.UnknownHostException;
  57.  
  58. /**
  59. *
  60. * @author student.kie
  61. */
  62. public class JavaApplication1 {
  63.  
  64. /**
  65. * @param args the command line arguments
  66. */
  67. public static void main(String[] args) throws UnknownHostException {
  68. // TODO code application logic here
  69.  
  70. InetAddress localhost = InetAddress.getLocalHost();
  71. System.out.println("getLocalHost:" + localhost);
  72. }
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. Zadanie 1
  81.  
  82.  
  83. /*
  84. * To change this license header, choose License Headers in Project Properties.
  85. * To change this template file, choose Tools | Templates
  86. * and open the template in the editor.
  87. */
  88. package javaapplication2;
  89.  
  90. import java.io.IOException;
  91. import java.net.InetAddress;
  92. import java.net.Socket;
  93. import java.net.UnknownHostException;
  94. import java.io.*;
  95.  
  96. /**
  97. *
  98. * @author student.kie
  99. */
  100. public class JavaApplication2 {
  101.  
  102. /**
  103. * @param args the command line arguments
  104. */
  105. public static void main(String[] args) throws IOException {
  106. // TODO code application logic here
  107. InetAddress addr = InetAddress.getByName("www.wp.pl");
  108. InetAddress adds = InetAddress.getByName("www.ug.gda.pl");
  109. InetAddress addw = InetAddress.getByName("www.onet.pl");
  110. InetAddress adde = InetAddress.getByName("www.interia.pl");
  111. int port = 80;
  112. try
  113. {
  114.  
  115. Socket socket = new Socket(addr, port);
  116. Socket socket2 = new Socket(adds,port);
  117. Socket socket3 = new Socket(addw,port);
  118. Socket socket4 = new Socket(adde,port);
  119. System.out.println(socket);
  120. System.out.println(socket2);
  121. System.out.println(socket3);
  122. System.out.println(socket4);
  123. }
  124. catch(UnknownHostException e){
  125. System.out.println("Nieznany host");
  126. }
  127. catch (Exception exc) {
  128. exc.printStackTrace();
  129. }
  130. }
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement