列出来自linux的windows域组内容

时间:2015-12-31 15:58:13

标签: linux bash dns squid

我想列出包含用户的域组的内容&计算机,然后从dns解析计算机名称并为鱿鱼准备列表。

最好的方法是什么?我正在考虑使用bash或perl连接到ldap,但也许有更好的方法。

1 个答案:

答案 0 :(得分:1)

感谢您的帮助。我创建了这个脚本,似乎它正在工作。

#!/bin/bash

oIFS=$IFS
IFS=$'\n'

# list group members
members=( $(ldapsearch -h server -D 'user' -w 'passw' -x -b "DC=domain,DC=net" "(cn=Groupname)" | grep member | awk -F '[=,]' '{print $2}') )

for (( i=0; i<${#members[@]}; i++ ));
do
        member=( $(echo "${members[$i]}") )
        AccountType=$(ldapsearch -h server -D 'user' -w 'passw' -x -b "DC=domain,DC=net" "(cn=$member)" | grep sAMAccountType | awk '{print $2}')
        if [ "$AccountType" == "805306369" ]
        then
                # this member is PC, let's resolve its IP
                host=$(host $member.domain.net)
                if [ $? -eq 0 ]; then
                        ip=$(echo $host| awk '{print $4}')
                        echo "$member has ip $ip"
                else
                        echo "WARNING: $member not found!"
                fi
        elif [ "$AccountType" == "805306368" ]
        then
                echo "$member is User"
        else echo "$member is neither PC, nor User"
        fi
done

IFS=$oIFS