From: gotoken@... (GOTO Kentaro) Date: 2000-05-05T04:13:56+09:00 Subject: [ruby-list:22277] Re: host.conf $B$O;2>H$7$J$$$N!)(B ごとけんです In message "[ruby-list:22275] host.conf は参照しないの?" on 00/05/05, Uechi Yasumasa writes: >自宅のコンピュータではネームサーバを動かさずに /etc/hosts で名前 >解決をしているのですが、自分の IPアドレスを引くのにプロバイダへ接 >続してしまい悲しい思いをしてしまいます。 > >irb(main):005:0> TCPsocket.getaddress('localhost') >"127.0.0.1" 意図によると思うんですけど、最初に自力で /etc/hosts を試すよ うに IPSocket::getaddress を再定義するのはどうですか?? require "socket" require "thread" class IPSocket IPSocketMutex = Mutex.new class << self def getaddress_from_file(host, file) #adrpat = "(?:\d{1,3})\.(?:\d{1,3})\.(?:\d{1,3})\.(?:\d{1,3})" IPSocketMutex.synchronize { unless @etc_hosts @etc_hosts = {} File::open(file).collect{|line| line.gsub!(/(\s+)?#.*/, "") # deletes comment if /^\s*$/ !~ line adr, *name = line.split name.each{|i| @etc_hosts[i] = adr} end } end } @etc_hosts[host] end alias __getaddress__ getaddress def getaddress(host, file = "/etc/hosts") getaddress_from_file(host, file) || __getaddress__(host) end end end if __FILE__ == $0 p TCPSocket.getaddress("localhost") # p TCPSocket.getaddress("www.ruby-lang.org") end