TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ramya k
NA
14
2.6k
how to find the username using Ipaddress or Hostname?
Jan 3 2019 1:02 AM
I have find the Ipaddress and Hostname using the active directory ComputerPrincipal method.but not find the username in this method.i need the username in my domain .how to do this?
here it my code
namespace Directory
{
class Program
{
static void Main(string[] args)
{
using (var context = new PrincipalContext(ContextType.Domain, "xxx.com"))
{
using (var searcher = new PrincipalSearcher(new ComputerPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
var auth = result as AuthenticablePrincipal;
var userName = auth.UserPrincipalName;
if (auth != null)
{
Console.WriteLine("Name: " + auth.Name);
Console.WriteLine("Last Logon Time: " + auth.LastLogon);
Console.WriteLine("UserName: " + auth.UserPrincipalName);
if (auth.Name != "Txx-Cxx-Gxx-Pxx")
{
IPAddress[] ipaddress = Dns.GetHostAddresses(auth.Name);
foreach (IPAddress ipaddr in ipaddress)
{
Console.WriteLine(ipaddr);
}
Console.WriteLine();
}
else
{
Console.WriteLine("Error");
}
}
}
}
Console.ReadLine();
Reply
Answers (
2
)
how to find the Ipaddress using username ?
How to add users to Active Directory from another domain?