In Go
application client make HTTP request. I know the IP address of the client who make the request.
Is it possibly to know user information (username, email, e.t.c) by IP address from Active Directory by LDAP query? What kind of filter I need to use?
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
if err != nil {
log.Fatal(err)
}
defer l.Close()
searchRequest := ldap.NewSearchRequest(
"dc=example,dc=com", // The base dn to search
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
"(&(objectClass=organizationalPerson))", // The filter to apply
[]string{"dn", "cn"}, // A list attributes to retrieve
nil,
)
sr, err := l.Search(searchRequest)
if err != nil {
log.Fatal(err)
}
for _, entry := range sr.Entries {
fmt.Printf("%s: %v
", entry.DN, entry.GetAttributeValue("cn"))
}
Active Directory does not store the IP or computer name that each person uses. Trying to match a user with a computer is difficult because a person can usually log in from any computer.
If you really want that information, there are a couple ways:
\\IPAddress\c$\Users
and check which profile was most-recently used.