2015年12月23日 星期三
LDAP filter 語法,windows ad 取出所有正常帳號
(&(objectCategory=person)(objectClass=user)(primaryGroupID=513)(|(useraccountcontrol=512)(useraccountcontrol=66048))))
2015年12月21日 星期一
PHP 查詢 windows AD 帳號範例(取出所有帳號)
<?php
$domain = 'domain';
$ldaprdn = 'userid';
$ldappass = 'password';
$ldapconn = ldap_connect($domain) or die("無法連接至 $domain");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
if ($ldapconn) { // binding to ldap server
// $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
$ldapbind = ldap_bind($ldapconn, $ldaprdn . '@' . $domain, $ldappass);
// verify binding
if ($ldapbind) {
$filter = "(sAMAccountName=*)";
$_dn = str_replace('.', ',dc=', "dc=". $domain);
$result = ldap_search($ldapconn, $_dn, $filter);
$info = ldap_get_entries($ldapconn, $result);
print_r($info);
} else {
echo "認證失敗...";
}
}
?>
$domain = 'domain';
$ldaprdn = 'userid';
$ldappass = 'password';
$ldapconn = ldap_connect($domain) or die("無法連接至 $domain");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
if ($ldapconn) { // binding to ldap server
// $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
$ldapbind = ldap_bind($ldapconn, $ldaprdn . '@' . $domain, $ldappass);
// verify binding
if ($ldapbind) {
$filter = "(sAMAccountName=*)";
$_dn = str_replace('.', ',dc=', "dc=". $domain);
$result = ldap_search($ldapconn, $_dn, $filter);
$info = ldap_get_entries($ldapconn, $result);
print_r($info);
} else {
echo "認證失敗...";
}
}
?>
2015年12月7日 星期一
使用bash script 取得系統目前 TCP 連線資訊
oIFS=$IFS;
IFS=$'\n';
for line in $(cat /proc/net/tcp6 |grep -v address);
do
IFS=$oIFS;
line=($line);
IFS=:
local_address=(${line[1]})
echo -n $((16#${local_address[0]:6:2})).\
$((16#${local_address[0]:4:2})).\
$((16#${local_address[0]:2:2})).\
$((16#${local_address[0]:0:2})):\
$((16#${local_address[1]}))
local_address=(${line[2]})
echo " <= " $((16#${local_address[0]:6:2})).\
$((16#${local_address[0]:4:2})).\
$((16#${local_address[0]:2:2})).\
$((16#${local_address[0]:0:2})):\
$((16#${local_address[1]}))
IFS=$'\n';
done;
IFS=$oIFS;
IFS=$'\n';
for line in $(cat /proc/net/tcp6 |grep -v address);
do
IFS=$oIFS;
line=($line);
IFS=:
local_address=(${line[1]})
echo -n $((16#${local_address[0]:6:2})).\
$((16#${local_address[0]:4:2})).\
$((16#${local_address[0]:2:2})).\
$((16#${local_address[0]:0:2})):\
$((16#${local_address[1]}))
local_address=(${line[2]})
echo " <= " $((16#${local_address[0]:6:2})).\
$((16#${local_address[0]:4:2})).\
$((16#${local_address[0]:2:2})).\
$((16#${local_address[0]:0:2})):\
$((16#${local_address[1]}))
IFS=$'\n';
done;
IFS=$oIFS;
訂閱:
文章 (Atom)