通过Net::Ping 理解Perl的面向对象
来源:互联网 发布:.net是编程语言吗 编辑:程序博客网 时间:2024/05/16 12:11
<pre name="code" class="sql">v-dev-redis01:/root# cat a1.pl sub check_dns{ use LWP::UserAgent; use Net::Ping;$web = shift; $p = Net::Ping->new("icmp"); if ($p->ping($web,2)){ return 1;} else { return 0;}} ;$var=&check_dns("$ARGV[0]"); print "$var\n";v-dev-redis01:/root# perl a1.pl www.zjtest.com1 If a default timeout ($def_timeout) in seconds is provided, it is used when a timeout is not given to the ping() method (below). The timeout must be greater than 0 and the default, if not specified, is 5 seconds.jrhmpt01:/root# cat a3.pl use Net::Ping;$p = Net::Ping->new("icmp");use Data::Dumper; my $xx= Dumper($p); print "111111111\n"; print $xx; print "\n"; jrhmpt01:/root# perl a3.pl 111111111$VAR1 = bless( { 'proto_num' => 1, 'proto' => 'icmp', 'data' => '', 'device' => undef, 'tos' => undef, 'data_size' => 0, 'pid' => 30484, 'econnrefused' => undef, 'fh' => bless( \*Symbol::GEN0, 'FileHandle' ), 'timeout' => 5, 'local_addr' => undef, 'seq' => 0, 'retrans' => '1.2' }, 'Net::Ping' );生产$p 这个对象,sub new{ my ($this, $proto, # Optional protocol to use for pinging $timeout, # Optional timeout in seconds $data_size, # Optional additional bytes of data $device, # Optional device to use $tos, # Optional ToS to set ) = @_; my $class = ref($this) || $this; my $self = {}; my ($cnt, # Count through data bytes $min_datasize # Minimum data bytes required ); bless($self, $class);其中$class is Net::Ping$self 是$VAR1 = bless( {}, 'Net::Ping' );sub ping{ my ($self, $host, # Name or IP number of host to ping $timeout, # Seconds after which ping times out ) = @_; my ($ip, # Packed IP number of $host $ret, # The return value $ping_time, # When ping began );ping 方法的第一个参数是$self 对象第2个参数是 域名或者IP地址第三个参数是 超时秒数生产$p 这个对象, Functions Net::Ping->new([$proto [, $def_timeout [, $bytes [, $device [, $tos ]]]]]); Create a new ping object. All of the parameters are optional. $proto specifies the protocol to use when doing a ping. The current choices are "tcp", "udp", "icmp", "stream", "syn", or "external". The default is "tcp".创建一个new 的ping 对象
0 0
- 通过Net::Ping 理解Perl的面向对象
- 面向对象的Perl
- 面向对象的Perl 1
- 面向对象的perl 2
- 面向对象的perl 3
- Perl的面向对象编程
- 面向对象的Perl 之一
- perl面向对象的概念
- Perl使用Net::Ping
- Perl Net::ping
- 面向对象的理解
- 面向对象的理解
- 面向对象的理解
- 面向对象的理解
- 面向对象的理解
- 面向对象的理解
- 面向对象的理解
- 面向对象的理解
- 用linux vconfig配置neutron VLAN试验
- 不看星座和属相,从你喜欢的编程语言看你是什么人
- 浅谈Android控件中的ListView优化
- mac上编译thrift 0.8.0
- tomcat集群基于redis共享session解决方案
- 通过Net::Ping 理解Perl的面向对象
- webserver报XFireFault: Unmarshalling Error: unexpected element (uri:"http://server.iflytek.com/", loc
- JavaScript
- C++入门学习笔记(四)--继承与多态
- 编译语言和解释语言(脚本)
- PPAPI插件与浏览器的通信
- VC C++ 操作 Excel 总结
- converting to execution character set: Invalid or incomplete multibyte or wide character
- PhoneWindow对象的创建