Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zadanie 3
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication3;
- import java.net.*;
- import java.util.Scanner;
- /**
- *
- * @author student.kie
- */
- public class JavaApplication3 {
- /**
- * @param args the command line arguments
- */
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- System.out.println("Podaj nazwę hosta");
- String host;
- host = sc.nextLine();
- try {
- InetAddress[] addresses = InetAddress.getAllByName(host);
- for (int i = 0; i < addresses.length; i++) {
- System.out.println(addresses[i]);
- }
- }
- catch (UnknownHostException e) {
- System.out.println("Nieznany host");
- }
- }
- }
- Zadanie 2
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.net.InetAddress;
- import java.net.Socket;
- import java.net.UnknownHostException;
- /**
- *
- * @author student.kie
- */
- public class JavaApplication1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws UnknownHostException {
- // TODO code application logic here
- InetAddress localhost = InetAddress.getLocalHost();
- System.out.println("getLocalHost:" + localhost);
- }
- }
- Zadanie 1
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication2;
- import java.io.IOException;
- import java.net.InetAddress;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.io.*;
- /**
- *
- * @author student.kie
- */
- public class JavaApplication2 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- // TODO code application logic here
- InetAddress addr = InetAddress.getByName("www.wp.pl");
- InetAddress adds = InetAddress.getByName("www.ug.gda.pl");
- InetAddress addw = InetAddress.getByName("www.onet.pl");
- InetAddress adde = InetAddress.getByName("www.interia.pl");
- int port = 80;
- try
- {
- Socket socket = new Socket(addr, port);
- Socket socket2 = new Socket(adds,port);
- Socket socket3 = new Socket(addw,port);
- Socket socket4 = new Socket(adde,port);
- System.out.println(socket);
- System.out.println(socket2);
- System.out.println(socket3);
- System.out.println(socket4);
- }
- catch(UnknownHostException e){
- System.out.println("Nieznany host");
- }
- catch (Exception exc) {
- exc.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement