java - get only the website name from domain name of url -


i need convert list of urls host name. tried below mentioned code:

url neturl = new url(url);  string host = neturl.gethost(); 

the above mentioned code producing output shown below:

a95-101-128-242.deploy.akamaitechnologies.com a23-1-242-192.deploy.static.akamaitechnologies.com edge-video-shv-01-lht6.fbcdn.net 

i want website name above output shown below:

akamaitechnologies akamaitechnologies fbcdn 

please help. thanks

if want parse url, use java.net.uri. java.net.url has bunch of problems -- equals method dns lookup means code using can vulnerable denial of service attacks when used untrusted inputs.

public static string getdomainname(string url) throws urisyntaxexception {   uri uri = new uri(url);   string domain = uri.gethost();   return domain.startswith("www.") ? domain.substring(4) : domain; } 

this should work.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -