Storage
[IP Detection Program] IP 클래스 구분/식별 코드 in Java
rhys
2014. 8. 7. 16:03
반응형
IP Address Classes A-E
IP 주소의 다섯 클래스 A~E, 이를 분류해보자.
네트워크 관련 과제 중 멀티캐스트와 유니캐스트를 각기 다른 소켓으로 다루기 위해 찾았던 코드인데,
32개의 이진수로 표시되는 IP주소를 이용해 클래스를 구분한다.
- /*
- Program for IP (Internet Protocol) Class Detection in Java
- Author: Khushang Mehta Author Link: https://www.facebook.com/khushang.mehta
- www.pracspedia.com
- */
- class IpClassDetection
- {
- {
- int ip[]=new int[4];
- int i=0,j=0,k=0,remainder;
- String bin;
- while(j!=3)
- {
- while(i < args[0].length() && args[0].charAt(i++)=='.')
- {
- k=i;
- }
- }
- if(ip[0] >-1 &&ip[0] < 256 && ip[1] > -1 && ip[1] < 256 && ip[2] > -1 && ip[2] < 256 && ip[3] > -1 && ip[3] < 256)
- {
- if(bin.charAt(0)=='0')
- {
- }
- else
- {
- if(bin.charAt(1)=='0')
- {
- }
- else
- {
- if(bin.charAt(2)=='0')
- {
- }
- else
- {
- if(bin.charAt(3)=='0')
- else
- }
- }
- }
- }
- else
- }
- }
- /*
- Output :-
- C:\Users\Student>java IpClassDetection 172.17.16.256
- Ip is invalid
- C:\Users\Student>java IpClassDetection 172.17.16.52
- Ip is valid
- The Ip entered is a Class B Address
- Net ID :- 172.17
- Host ID :- 16.52
- */
반응형