ソフトウエア基礎
ohmi@rsch.tuis.ac.jp

ネットワーク(1) 解答例

課題net-1

ポート69番のサービスはtftpである。 またkerberosサービスのポート番号は、88番である。

課題net-2

例えば以下のようになる。

pcxxxx[xxxx]511:~/% telnet localhost 13
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
16 DEC 2004 18:36:55 JST
Connection closed by foreign host.
pcxxxx[xxxx]512:~/%

課題net-3

以下のようになる。

pcxxxx[xxxx]515:~/% telnet www.edu.tuis.ac.jp 13
Trying 202.26.148.102...
telnet: connect to address 202.26.148.102: Connection refused
pcxxxx[xxxx]516:~/%

接続が拒否されている。 セキュリティ上の問題などから拒否する設定にしている。

課題net-4

例えば、以下のようになる。

pcxxxx[xxxx]501:~% telnet www.rsch.tuis.ac.jp 80
Trying 202.26.148.102...
Connected to www.rsch.tuis.ac.jp.
Escape character is '^]'.
GET /~ohmi/software-basic/network-test.html HTTP/1.1
Host: www.rsch.tuis.ac.jp
Connection: close

HTTP/1.1 200 OK
Date: Thu, 16 Dec 2004 09:42:13 GMT
Server: Apache/1.3.27 (Unix) mod_jk/1.2.3-dev PHP/4.2.2
Last-Modified: Mon, 29 Nov 2004 16:49:07 GMT
ETag: "1a8503-96-41ab5303"
Accept-Ranges: bytes
Content-Length: 150
Connection: close
Content-Type: text/html

<html>
<head>
<title>Network test</title>
</head>
<body>
<h1>Network test page</h1>
<address>joho-taro@hogehoge.tuis.ac.jp </address>
</body>
</html>
Connection closed by foreign host.
pcxxxx[xxxx]502:~%

課題net-5

以下は http://www.rsch.tuis.ac.jp/~ohmi/software-basic/network-test2.html にアクセスした例である。403 Forbidden となっており、 アクセスが許可されていないことが分かる。 ファイルを読む権限が与えられていないという原因が多い。

pcxxxx[xxxx]502:~% telnet www.rsch.tuis.ac.jp 80
Trying 202.26.148.102...
Connected to www.rsch.tuis.ac.jp.
Escape character is '^]'.
GET /~ohmi/software-basic/network-test2.html HTTP/1.1
Host: www.rsch.tuis.ac.jp
Connection: close

HTTP/1.1 403 Forbidden
Date: Thu, 16 Dec 2004 09:45:08 GMT
Server: Apache/1.3.27 (Unix) mod_jk/1.2.3-dev PHP/4.2.2
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

139
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>403 Forbidden</TITLE>
</HEAD><BODY>
<H1>Forbidden</H1>
You don't have permission to access
/~ohmi/software-basic/network-test2.html
on this server.<P>
<HR>
<ADDRESS>Apache/1.3.27 Server at www.rsch.tuis.ac.jp Port 80</ADDRESS>
</BODY></HTML>

0

Connection closed by foreign host.
pcxxxx[xxxx]503:~%

以下は http://www.rsch.tuis.ac.jp/~ohmi/software-basic/network-test3.html にアクセスした例である。404 Not Found となっており、 ファイルが見つからないことが分かる。 ファイルが存在していないという原因が多い。

pcxxxx[xxxx]503:~% telnet www.rsch.tuis.ac.jp 80
Trying 202.26.148.102...
Connected to www.rsch.tuis.ac.jp.
Escape character is '^]'.
GET /~ohmi/software-basic/network-test3.html HTTP/1.1
Host: www.rsch.tuis.ac.jp
Connection: close

HTTP/1.1 404 Not Found
Date: Thu, 16 Dec 2004 09:49:30 GMT
Server: Apache/1.3.27 (Unix) mod_jk/1.2.3-dev PHP/4.2.2
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

135
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL /~ohmi/software-basic/network-test3.html was not found
on this
 server.<P>
<HR>
<ADDRESS>Apache/1.3.27 Server at www.rsch.tuis.ac.jp Port 80</ADDRESS>
</BODY></HTML>

0

Connection closed by foreign host.
pcxxxx[xxxx]504:~%

課題net-6

例えば、http://www.edu.tuis.ac.jp/~s03999yy/ であった場合は、 以下のようになる。もちろんWebページが存在する場合である。

pcxxxx[xxxx]503:~% telnet www.edu.tuis.ac.jp 80
Trying 202.26.148.102...
Connected to www.edu.tuis.ac.jp.
Escape character is '^]'.
GET /~s03999yy/index.html HTTP/1.1
Host: www.edu.tuis.ac.jp
Connection: close

HTTP/1.1 200 OK
Date: Thu, 16 Dec 2004 09:53:18 GMT
Server: Apache/1.3.27 (Unix) mod_jk/1.2.3-dev PHP/4.2.2
Last-Modified: Fri, 30 Jan 2004 16:14:54 GMT
ETag: "de2af-c38-401a82fe"
Accept-Ranges: bytes
Content-Length: 3128
Connection: close
Content-Type: text/html

<html>
<head>
<span class=red>(途中省略)</span>
</body>
</html>
Connection closed by foreign host.
pcxxxx[xxxx]504:~%

課題net-7

自分のメールアドレスが、s03999yy@edu.tuis.ac.jp の場合、 以下のようにして送信する。

pcxxxx[xxxx]511:~% telnet mailhost.edu.tuis.ac.jp 25
Trying 202.26.148.110...
Connected to mailhost.edu.tuis.ac.jp.
Escape character is '^]'.
220 edu.tuis.ac.jp ESMTP Sendmail 8.12.11/8.11.6; Thu, 16 Dec 2004
18:58:41 +090
0
HELO pcxxxx.edu.tuis.ac.jp
250 edu.tuis.ac.jp Hello pcxxxx.edu.tuis.ac.jp [192.168.131.1], pleased to meet
you
MAIL FROM: s03999yy@edu.tuis.ac.jp
250 2.1.0 s03999yy@edu.tuis.ac.jp... Sender ok
RCPT TO: s03999yy@edu.tuis.ac.jp
250 2.1.5 s03999yy@edu.tuis.ac.jp... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: test mail
To: s03999yy@edu.tuis.ac.jp

Hello!
--
Yoyoyoyo yoyoyo 
.
250 2.0.0 iBG9wfLF069472 Message accepted for delivery
QUIT
221 2.0.0 edu.tuis.ac.jp closing connection
Connection closed by foreign host.
pcxxxx[xxxx]512:~%

届いたメールは以下のようになる。

Received: from pcxxxx.edu.tuis.ac.jp (pc3201.edu.tuis.ac.jp [192.168.131.1])
	by edu.tuis.ac.jp (8.12.11/8.11.6) with SMTP id iBG9wfLF069472
	for s03999yy@edu.tuis.ac.jp; Thu, 16 Dec 2004 18:59:23 +0900
Message-Id: <200412160959.iBG9wfLF069472@edu.tuis.ac.jp>
X-UIDL: 97R!!RM("!T[e"!(#~!!
Subject: test mail
From: Yoyoyoyo yoyoyo 
To: s03999yy@edu.tuis.ac.jp
Date: Thu, 16 Dec 2004 18:58:41 +0900

Hello!
--
Yoyoyoyo yoyoyo 

課題net-8

自分のメールアドレスが、s03999yy@edu.tuis.ac.jp の場合、 以下のようにして送信する。

pcxxxx[xxxx]511:~% telnet mailhost.edu.tuis.ac.jp 25
Trying 202.26.148.110...
Connected to mailhost.edu.tuis.ac.jp.
Escape character is '^]'.
220 edu.tuis.ac.jp ESMTP Sendmail 8.12.11/8.11.6; Thu, 16 Dec 2004
18:58:41 +090
0
HELO pcxxxx.edu.tuis.ac.jp
250 edu.tuis.ac.jp Hello pcxxxx.edu.tuis.ac.jp [192.168.131.1], pleased to meet
you
MAIL FROM: hogehoge@ohmi.rsch.tuis.ac.jp
250 2.1.0 hogehoge@ohmi.rsch.tuis.ac.jp... Sender ok
RCPT TO: s03999yy@edu.tuis.ac.jp
250 2.1.5 s03999yy@edu.tuis.ac.jp... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: test mail
To: s03999yy@edu.tuis.ac.jp

Hello!
--
HOGEHOGE 
.
250 2.0.0 iBG9wfLF069472 Message accepted for delivery
QUIT
221 2.0.0 edu.tuis.ac.jp closing connection
Connection closed by foreign host.
pcxxxx[xxxx]512:~%

届いたメールは以下のようになる。

Received: from pcxxxx.edu.tuis.ac.jp (pc3201.edu.tuis.ac.jp [192.168.131.1])
	by edu.tuis.ac.jp (8.12.11/8.11.6) with SMTP id iBG9wfLF069472
	for s03999yy@edu.tuis.ac.jp; Thu, 16 Dec 2004 18:59:23 +0900
Message-Id: <200412160959.iBG9wfLF069472@edu.tuis.ac.jp>
X-UIDL: 97R!!RM("!T[e"!(#~!!
Subject: test mail
From: hogehoge@ohmi.rsch.tuis.ac.jp
To: s03999yy@edu.tuis.ac.jp
Date: Thu, 16 Dec 2004 18:58:41 +0900

Hello!
--
HOGEHOGE 

このように自分のメールアドレス以外を差出人としてメールを送ることがで きる。

課題net-9

import java.net.*;
public class InetAddressTest4 {
    public static void main(String[] args){
        try {
            InetAddress address = InetAddress.getByName("202.26.148.102");
            System.out.println("HostName is " + address.getHostName());
        } 
        catch (UnknownHostException e) {
            System.out.print("This host is unknown");
        }
    }
}

実行結果

HostName is ftpsvr.edu.tuis.ac.jp

備考: 202.26.148.102はwww.edu.tuis.ac.jpなど複数のホスト名を持っているが、 正式なホスト名は ftpsvr.edu.tuis.ac.jp としてDNSに登録されている。

課題net-10

import java.net.*;
public class InetAddressTest5 {
    public static void main(String[] args){
        try {
            InetAddress address = InetAddress.getByName("www.yahoo.co.jp");
            System.out.println("HostName is " + address.getHostAddress());
        } 
        catch (UnknownHostException e) {
            System.out.print("This host is unknown");
        }
    }
}

実行結果

pcxxxx[xxxx]532:~/Java% java InetAddressTest5
HostName is 210.81.150.5
pcxxxx[xxxx]533:~/Java% java InetAddressTest5
HostName is 202.229.199.136
pcxxxx[xxxx]534:~/Java% java InetAddressTest5
HostName is 211.14.15.5
pcxxxx[xxxx]535:~/Java% java InetAddressTest5
HostName is 211.14.15.5
pcxxxx[xxxx]536:~/Java% java InetAddressTest5
HostName is 202.229.198.216
pcxxxx[xxxx]537:~/Java%

このように毎回異なるIPアドレスが返される。 複数のWebサーバを用意して、その1つのIPアドレスを返すことで、 負荷分散を行なっている。

課題net-11

import java.net.*;
public class InetAddressTest6 {
    static boolean isIPAddress(String s) {
	for (int i = 0; i < s.length(); i++) {
	    char c = s.charAt(i);
	    if (c != '.' && !(c >= '0' && c <= '9')) {
		return false;
	    }
	}
	return true;
    }

    public static void main(String[] args){
	if (args.length != 1) {
	    System.err.println("Usage: java InetAddressTest6 arg1");
	    System.exit(-1);
	}
        try {
            InetAddress address = InetAddress.getByName(args[0]);
	    if (isIPAddress(args[0])) {
		System.out.println("HostName is " + address.getHostName());
	    } else {
		System.out.println("IP Address is " + address.getHostAddress());
	    }
        } 
        catch (UnknownHostException e) {
            System.out.print("This host is unknown");
        }
    }
}

ソフトウエア基礎

ohmi@rsch.tuis.ac.jp

Valid HTML 4.01!