Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- StringBuilder
- 프로그래머스스쿨
- c#
- JavaScript
- 스프링부트
- AssertJ
- join()
- class
- Python
- GIT
- Java
- thread
- 파이썬
- 자바스크립트
- 자바
- 메소드
- JS
- Dict
- SSL
- SpringBoot
- 객체
- 저장소
- event
- synchronized
- array
- Docker Desktop
- Swing
- docker
- 클래스
- 배열
Archives
- Today
- Total
정리노트
[자바/java] IP주소 찾기 / 사이트 내용 받기 본문
package shapeTest;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class ShapeTest {
public static void main(String[] args) throws IOException {
String hostName = "www.naver.com";
try {
InetAddress address = InetAddress.getByName(hostName);
InetAddress myAddress = InetAddress.getLocalHost();
System.out.println("IP주소: " + address.getHostAddress());
System.out.println("나의 IP주소: " + myAddress.getHostAddress());
System.out.println(myAddress.getHostName()); // 호스트 이름 찾기
} catch (UnknownHostException e) {
System.out.println(hostName + "의 IP주소를 찾을 수 없습니다.");
}
}
}
package connectionReaderURL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL site = new URL("https://www.naver.com");
URLConnection url = site.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(url.getInputStream()));
String inLine;
while ((inLine = in.readLine()) != null) {
System.out.println(inLine);
}
in.close();
}
}
// HTML 내용을 받아서 출력한다.
728x90
'프로그래밍 > Java' 카테고리의 다른 글
[자바/java] 간단 채팅 프로그램 / UDP 서버, 클라이언트 (0) | 2023.02.07 |
---|---|
[자바/java] 서버, 클라이언트 접속 (간단한 채팅) / TCP 프로토콜 (0) | 2023.02.07 |
[자바/java] synchronized 데이터 중복사용 방지, 좌석예약 (0) | 2023.02.05 |
[자바/java] Thread 활용 두 개 이미지 이동 컨트롤 - 2 / join() (1) | 2023.02.05 |
[자바/java] 하나의 list 두 개 스레드 동작 합 구하기 (0) | 2023.02.05 |