How to know a domain name server in vb.net? - vb.net

I want a vb.net function. We give domain name, it gives the name servers and the IP.
What would the code be?
I know I can use webclient to scrap various whois sites. They don't like that and put password. I want the "good" way to do it.
Say google.com's name server is ns1.google.com I want to know what's the name server of google.com.
For example:
If we go to http://who.is/whois/google.com/
We will see that google.com has ns1.google.com ns2.google.com ns3.google.com and ns4.google.com
I want a function say FindNS("Google.com") to yield "ns1.google.com"

System.Net.Dns.GetHostEntry("ns1.google.com").AddressList;
This will return an array of all IPs linked to the hostname you provide.

Related

Specifying multiple Domain Bases in Rocket.Chat LDAP

On Rocket.Chat's LDAP configuration page, the helper text for Domain Base states that you should enter (emphasis mine):
The fully qualified Distinguished Name (DN) of an LDAP subtree you want to search for users and groups. You can add as many as you like; however, each group must be defined in the same domain base as the users that belong to it. If you specify restricted user groups, only users that belong to those groups will be in scope. We recommend that you specify the top level of your LDAP directory tree as your domain base and use search filter to control access.
Problem is, I don't know how to enter more than one.
My DN looks like this:
OU=IT,OU=Staff,DC=companyname,DC=local
And I want the following users to also be synced:
OU=Example,OU=Staff,DC=companyname,DC=local
But I don't know how to add them both, as the docs aren't clear, and the source code is even less clear.
I've tried the following ways:
Space separated
Semicolon separated
Ampersand (and double ampersand) separated
Wrapping them up in an array (e.g. ["OU=Example ...", "OU=IT ..."]) and as a JSON object
Pipe (and double pipe) separated
'Plus' separated (e.g. DC=local + OU=Example)
But no matter what I do, it won't sync users. The logs tell me:
Exception while invoking method 'ldap_sync_users' NoSuchObjectError: 0000208D: NameErr: DSID-03100238, problem 2001 (NO_OBJECT), data 0, best match of: at Object.Future.wait (/snap/rocketchat-server/511/node_modules/fibers/future.js:449:15) ...
I know I can set up a group restriction so only users in a certain group will be synced, but the helper text says I can use multiple DNs, and I want to know how to use multiple DNs
After reading RFC-4514, I discovered I should construct my DN like so:
OU=Example+OU=IT,OU=Staff,DC=companyname,DC=local
With the plus occurring between the two OUs I wish to add. Now my users are syncing correctly.

Get Country code from VBA and LDAP

I have email id of the members and I am executing following quesy
The command text is
UserDomain = VBA.Environ("UserDomain")
cmd.CommandText = "SELECT cn, mail, c FROM 'LDAP://" & UserDomain & "' WHERE mail = 'r.khenat#abc.com'"
Above code works well on my machine for me and my teammates, however if I use the same code to get the details of the team mates who are in different domain, I get no information.
Instead of UserDomain, what root value I need to put so that I can get the required information.
Any idea?
I managed to get it done by hard coding the domain names and adding it in an Array. I iterated through array to fetch the required details.
You can only ask a domain for users that belong to that domain, so the current domain you are querying will know nothing about e.g. my email, just as my domain will know nothing about your email.
You can try asking my domain about my email if you want, but you won't have any access to it. In the same way I can try asking your domain about its members but if I have access them your domain has been set up very very badly. Only a properly authorised member of a domain should be able to ask that domain such questions, and them only when logged onto a machine which is also a member of that same domain, and is also connected to it.
So no, the query you want to run will not work, by design.

MVC user's full name in Url, how to handle duplicates

I want to setup the following url in my MVC4 website, using the user's full name in the url:
http://www.myapp.com/profile/steve-jones
I have setup the following route in Global.asax:
routeCollection.MapRoute(
"profile", "profile/{userName}",
new { controller = "myController", action = "profile", userName = string.Empty
});
And I can take the parameter 'steve-jones' and match it to a user with matching name. My only problem though is, what if there is more than one 'Steve Jones', how can I handle this?
Does anyone know of a workaround/solution to this so that I can use a user's full name as part of the url and still be able to retrieve the correct user in the controller method?
Am I forced into including the user's id with the url (something that I do not want to appear)?
The usual way of handling this is by appending a number when creating the profiles. So if "steve-jones" is already a name in the database, then make the user's display name "steve-jones2". You basically have to insist that all profile urls are unique, which includes updating any existing database and account creation code.
Alternatively (and/or additionally), if two same names are found then have the script reroute to a disambiguation page where the user is presented with links and snippet of profile info of the many existing Steve Joneseses so they can go to the full correct profile.
Another way of handling it is by giving all user profiles an additional numeric code on the end. At my university all logins are based on name, so they give everyone pseudo-random 3-digit extensions so that they are safe as long as they don't get 1000 people with the exact same names :)
Some people might be happier being steve-jones-342 if there is no steve-jones or steve-jones1, if you're concerned.

SQL related wonky error if there is no HTTP in the URL

select
wu.ACCOUNT_NUMBER as WS_ACCOUNT_NUMBER,
wu.LIFETIME_REVENUE as WS_LIFETIME_REVENUE,
wu.FIRST_NAME||' '||wu.LAST_NAME as WS_ACCOUNT_NAME,
wu.PRIMARY_EMAIL as WS_ACCOUNT_EMAIL,
wu.TIME_CREATED as WS_ACCOUNT_TIME_CREATED,
wuu.URL as BUSINESS_URL
from
WUSER wu
left outer join WUSER_URL wuu on wu.ACCOUNT_NUMBER = wuu.ACCOUNT_NUMBER
where
wu.ACCOUNT_NUMBER = 123456789;
URL displayed on the screen is hyperlink and should take us to the website on clicking it. Problem is that it works only and only when it has a HTTP protocol attached prior to it in the Oracle db.
for example, it works when the url in db is http://www.google.com or http://google.com
but it FAILS when the url is google.com or www.google.com
Our client is very specific about this requirement and wants to be able to hop over to the website when there is no HTTP to the URL record in the db.
**What are the possible solutions? Can I write a conditional insert to check record by record if there is HTTP, and if not, then append it somehow ?
If yes, please tell me the SQL too**
Please Help!!!!!!
Are you able to check the data before it's being inserted, and pre-pend the HTTP://?
Conditional code to put HTTP:// in front of the string could be...
CASE WHEN UPPER(wuu.URL) LIKE 'HTTP://%'
THEN wuu.UR
ELSE 'HTTP://' || wuu.URL
END
(It's only on several lines to make it easier to read.)

Connection strings for different users

How do I send two users coming from different company domains to different SQL databases to retrieve/store data? I use Application variables to store the connection strings and the Request.ServerVariables("LOGON_USER") variable is an effective way to get the domain name. Is the GLOBAL.AsA file to be modified? The table names are exactly the same in both databases, so I think changing the connection strings based on the user domain should do the trick.
User A with domain ABC --> Application("ConnecttoDB") send to database A
User B with domain XYZ --> Application("ConnecttoDB") send to database B
I have roughly 900+ classic ASP pages so I would really hate to add a bunch of IF-THEN's to choose the correct database in each page. All ideas are greatly appreciated!
UPDATE: To make things simple I'm envisioning one single Application variable (i.e.: ConnecttoDB) However, wouldn't its value be constantly changing every time a different user gets access and altering page results?
You can't use an Application variable since that's shared across all users. This would be a race condition. Instead you'll need to use the Session object to store the connection and then use that whenever you need to connect to the DB.
myDB=Server.CreateObject("ADODB.Connection")
StrConn = Session("ConnecttoDB")
myDB.Open StrConn
Here's one way of doing it:
I'm guessing that your classes for your web page codebehind files inheit the Page class. Create a new class file in your ASP.net project that inherits Page. Call it JorgePage. Then, make your codebehind file classes inherit JorgePage.
In JorgePage, write two functions:
private string getUsersDomain()
{
// returns the user's domain
}
protected string getUsersConnectionString()
{
switch (getUsersDomain().ToUpper())
{
case "ABC":
return Application("ConnecttoDB_ABC");
break;
case "xYZ":
return Application("ConnecttoDB_XYZ");
break;
}
}
Now, the function getUsersConnectionString() is available in the context of all your pages and returns the correct connection string. Furthermore, you have the code in only one place, so if you need to change the logic later, you can do so easily.
Given that you're using classic ASP, you can define a function to return the appropriate connection string in another .asp file and use the #include directive to add it to all your pages.