您的位置:首页 > 理论基础 > 计算机网络

[python&php 网络编程]获取远程机器的信息

2015-11-19 17:12 1151 查看
1.python写法

import socket

def get_remote_machine_info():
remote_host = 'www.python.org'
try:
print "IP address of %s: %s" %(remote_host, socket.gethostbyname(remote_host))
except socket.error, err_msg:
print "%s: %s" %(remote_host, err_msg)

if __name__ == '__main__':
get_remote_machine_info()


2.php写法

<?php

function get_remote_machine_info(){
$remote_host = 'www.python.org';
try{
printf("IP address of %s: %s\n", $remote_host, gethostbyname($remote_host));
}catch(Exception $e){
printf("%s: %s\n", $remote_host, $e->getMessage());
}
}

get_remote_machine_info();

代码比较简单 但执行起来还是php比较慢~

转载请标注原文地址:http://blog.csdn.net/ddjohn/article/details/49930455
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: