-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.php
73 lines (62 loc) · 1.61 KB
/
sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/php
<?php
/* $Id$ */
if ( ! extension_loaded ('krisp') ) {
if ( version_compare (PHP_VERSION, '5.4.0', '<') ) {
dl ('krisp.so');
} else {
fprintf (STDERR, "KRISP extension is not loaded\n");
exit (1);
}
}
$searches = array ('oops.org', 'kornet.net', 'yahoo.com', 'kldp.org');
/*
* open krips database
*
* resource krisp_open (database)
*
* if failed, return FALSE
*/
#$c = krisp_open ("/usr/share/krisp/krisp.dat", $err);
#$c = krisp_open ('asdf', $err);
#$c = krisp_open ('', $err);
#$c = krisp_open (NULL, $err);
$c = krisp_open ();
if ( $c === false ) {
echo "ERROR: {$err}\n";
return 1;
}
krisp_set_mtime_interval ($c, 0);
krisp_set_debug ($c);
foreach ( $searches as $v ) {
/*
* search krsip database
*
* object krisp_search (krsip resource, host)
* object krisp_search_ex (krsip resource, host[, table='krisp'])
*/
$r = krisp_search ($c, $v);
if ( $r === false )
continue;
print_r ($r);
krisp_set_debug ($c, false);
//break;
}
/*
* close krisp database
*/
krisp_close ($c);
echo "Get subnet mask with 192.168.10.44 - 192.168.10.58 => ";
$mask = krisp_netmask ('192.168.10.44', '192.168.10.58');
echo "{$mask->mask} : {$mask->prefix}\n";
echo " * network address : " . krisp_network ('192.168.10.44', $mask->mask) . "\n";
echo " * broadcast address : " . krisp_broadcast('192.168.10.44', $mask->mask) . "\n";
echo "\nNetmask <-> Prefix\n";
unset ($mask);
$mask = '255.255.255.128';
echo " * Given Mask : {$mask}\n";
$prefix = krisp_mask2prefix ($mask);
echo " * Prefix : {$prefix}\n";
$mask = krisp_prefix2mask ($prefix);
echo " * Mask : {$mask}\n";
?>