我需要知道十台计算机的状态。
尝试使用" PING",我在十秒内收到信息。
我想更快捷地在 Windows7 64 中获取此信息。
代码:
from platform import system as system_name # Returns the system/OS name
from os import system as system_call # Execute a shell command
def ping(host):
# Ping parameters as function of OS
parameters = "-n 1" if system_name().lower()=="windows" else "-c 1"
# Pinging
return system_call("ping " + parameters + " " + host) == 0
谢谢!
答案 0 :(得分:1)
尝试使用子流程
#include <stdio.h>
#include <string.h>
void print_array(size_t n, int a[n][n]);
void rotate_array(size_t n, int a[n][n]);
int main(void)
{
size_t arr_sz = 5;
int arr[arr_sz][arr_sz];
for (size_t i = 0; i < arr_sz; i++) {
for (size_t j = 0; j < arr_sz; j++) {
arr[i][j] = i * arr_sz + j + 1;
}
}
puts("Before rotation:");
print_array(arr_sz, arr);
putchar('\n');
rotate_array(arr_sz, arr);
puts("After rotation:");
print_array(arr_sz, arr);
putchar('\n');
return 0;
}
void print_array(size_t n, int a[n][n])
{
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
printf("%5d", a[i][j]);
}
putchar('\n');
}
}
void rotate_array(size_t n, int a[n][n])
{
int rotated[n][n];
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
rotated[i][j] = a[n - j - 1][i];
}
}
memcpy(a, rotated, sizeof a[0][0] * n * n);
}