hostname

What would you like to see in CSPro?
Post Reply
noel
Posts: 25
Joined: June 16th, 2012, 7:32 pm
Location: Libreville, Gabon

hostname

Post by noel »

May we have a function giving, in windows the hostname of the computer used ? The GetdeviceId is interesting as function but need to completed by a function giving the hostname of the computer.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: hostname

Post by josh »

We will discuss adding a hostname function. What exactly would you use it for?

In the meantime in Windows you could you emulate it with execsystem:

Code: Select all

PROC GLOBAL
file TMPFILE;

function alpha getHostName()
	string tmppath = concat(pathname(Temp), "hostname.txt");
	string batpath = concat(pathname(Temp), "gethostname.bat");
	setfile(TMPFILE, batpath);
	filewrite(TMPFILE, "echo");
	filewrite(TMPFILE, concat("hostname > ", tmppath));
	close(TMPFILE);
	execsystem(batpath, focus, wait);
	setfile(TMPFILE, tmppath);
	string hn;
	fileread(TMPFILE, hn);
	close(TMPFILE);
	filedelete(batpath);
	filedelete(tmppath);
	getHostName = hn;
end
noel
Posts: 25
Joined: June 16th, 2012, 7:32 pm
Location: Libreville, Gabon

Re: hostname

Post by noel »

I already use this function as you sugest. According to me, when you work with a network, the keyer affectation is made using the device's hostname and not their Mac information. In that occasion, hostname seems to be more usefull than Mac number.

In other hand, may we have a function to know if the internet connection is available or not?
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: hostname

Post by josh »

Thanks. That makes sense. The hostname is certainly nicer to look at than the mac id. There is also a getusername() function which on Windows will give you the name of the logged in user. This is not the hostname but if each keyer has a different login it might work.

We will add the hostname function to the todo list.

For checking if the network is connected, it is easy to see if networking is configured - i.e. if there is a network card that is enabled and connected to some router. It is not simple to determine in general if there is a working internet connection. For that the only way to be sure is to actually try to connect to some specific host. Basically it is easy to create a function that returns the equivalent of the little status bar network icon in Windows shows you but as you have probably seen there are times when that icon shows a working connection but you still cannot access the internet. Would you need a function that determines whether or not you can connect to a specific host or would be ok with one that just gives the same result as the network status icon?
noel
Posts: 25
Joined: June 16th, 2012, 7:32 pm
Location: Libreville, Gabon

Re: hostname

Post by noel »

I need a function that determines whether or not I can connect to a specific host. It can be used to check before synchronize data.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: hostname

Post by josh »

Got it. One idea we had to was to allow syncing with logic functions instead of having to write out a sync file. Something like:

Code: Select all

if sync_connect(FTP, myhost, myusername, mypassword) then
   sync_set_server_path("/data");
   sync_get(mydatafilename);
   sync_disconnect();
else
  errmsg("Failed to connect to host %s", myhost);
endif;
The idea is that for complicated synchronizations you would be able to download a file, read it and then get or put other files based on the contents of the file you downloaded.

If we had that then you could just use the sync_connect() function to check if you could connect to the host.
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: hostname

Post by htuser »

Dear all,
I have some bad ideas... It's to use the ping cmd ... Our teacher Gregory learn me how to write theses logics for writing a dos batch and use results within cspro. Please see (http://csprousers.org/forum/search.php? ... s=getmacid )

I think that's enough to detect internet or network by pinging external or local IP or hostnames.

@Josh, good idea for writing sync codes within logic! Does the latest codes you posted already have function in Cspro? And until now, in 10-20% of event, the syncing module require to start it 3-4 times before finalizing some task...mainly over LAN. It may be a bug...
Sincerely yours,
G.VOLNY, a CSProuser from Haiti, since 2004
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: hostname

Post by josh »

The latest code doesn't have this. This is just an idea we have been discussing. In the latest beta you can write out a sync file in logic and call execsync to launch it but there isn't any way to run logic in the middle of a sync.

For the problems you are having with sync lets not hijack this thread on hostname. Please start a new one. Also please try downloading one of the free FTP apps from Google Play and use it to transfer the same files you were doing in your sync. See if you get 10-20% failures there or not so we can see if it is an issue with sync or with the LAN/FTP server setup itself.
Post Reply