You are on page 1of 4

//**************** (Practical 14) XIII(1) ********************

import java.net.*;
import java.util.Scanner;

public class Practical1


{
public static void main(String a[])throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.print("enter the Host name : ");
String h_name = sc.next();
InetAddress ia = InetAddress.getByName(h_name);
System.out.println("IP Address = "+ia);

/*
//OUTPUT :

enter the Host name : google.com


.IP Address = google.com/142.250.192.78

*/
//**************** (Practical 15) XIII(1) ********************

import java.net.*;
import java.util.Scanner;

public class Practical1


{
public static void main(String a[])throws Exception
{
URL url1 = new URL("http://www.msbte.org.in");
System.out.println("Host Name = "+url1.getHost());
System.out.println("Protocol = "+url1.getProtocol());
System.out.println("port number = "+url1.getPort());
System.out.println("File = "+url1.getFile());

}
}

/*
OUTPUT :
Host Name = www.msbte.org.in
Protocol = http
port number = -1
File =

*/
//******************** (Practical 15) XIII(2)
************************

import java.io.InputStream;
import java.net.*;
import java.util.Date;

public class Practical1


{
public static void main(String a[])throws Exception
{
int i;
URL url1 = new URL("http://www.msbte.org.in");
URLConnection urlc = url1.openConnection();

System.out.println("Date = "+new Date(urlc.getDate()));


System.out.println("Content type = "+urlc.getContentType());
System.out.println("Content length =
"+urlc.getContentLength());
System.out.println("Content = ");

if(urlc.getContentLength()!=0)
{
InputStream is = urlc.getInputStream();

while ((i=is.read())!=-1)
{
System.out.print((char)i);
}

}
else
{
System.out.println("there is no content present in this
site...!");
}

}
}

/*
OUTPUT =
Date = Mon Oct 09 22:03:02 IST 2023
Content type = text/html
Content length = 524077
Content =


<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Maharashtra State Board of Technical Education, Mumbai
, India</title>
<meta https-equiv="content-language" content="en-US">
<meta name="language" content="English">
<meta name='google-site-verification' content='Maharashtra
State Board of Technical Education, Mumbai' />
.
.
.
.
.
.
<button onclick="topFunction()" class="scrollup" id="myBtn"
title="Go to top"><img
src="https://msbte.org.in/slide/img/Maharashtra-State-Board-of-
Technical-Education--Mumbai.jpg" alt="ScrollTop"></button>

<!-- container ends here -->


</body>

</html>

*/

You might also like