I have two pc's on the same network.
One of them I know the current time, the other is inaccessible by me.
I have found that you can ping another machine to get a timestamp from it.
So it would look like ...
PC1 time ping sent
PC2 time ping received
PC2 time return ping sent
PC1 time return recieved
I have the following code
Dim pingbyte(31) As Byte
Dim timestamp As New Net.NetworkInformation.PingOptions
PingReturn = New Net.NetworkInformation.Ping
sReturn = PingReturn.Send("xxx.xxx.xxx.xxx")
These three lines are in the declarations section.
' Ping
Dim PingReturn As System.Net.NetworkInformation.Ping
Dim sReturn As System.Net.NetworkInformation.PingReply
Dim TimeReturn As System.Net.NetworkInformation.IcmpV4Statistics
TommySzalapski
See if your numbers match what you see in netstat -s
(run netstat -s from a command prompt and look in the ICMP4 stats section)
TommySzalapski
I don't know if there is a user-friendly way to send ICMP Get Timestamp messages using VB.NET. If you really need to do this, you may need to build the packet manually, byte by byte.
if (argc > 2)
{
fwprintf(stderr, L"Usage: %s [\\\\ServerName]\n", argv[0]);
exit(1);
}
// The server is not the default local computer.
//
if (argc == 2)
pszServerName = (LPTSTR) argv[1];
//
// Call the NetRemoteTOD function.
//
nStatus = NetRemoteTOD((LPCWSTR) pszServerName,
(LPBYTE *)&pBuf);
//
// If the function succeeds, display the current date and time.
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
{
fprintf(stderr, "\nThe current date is: %d/%d/%d\n",
pBuf->tod_month, pBuf->tod_day, pBuf->tod_year);
fprintf(stderr, "The current time is: %d:%d:%d\n",
pBuf->tod_hours, pBuf->tod_mins, pBuf->tod_secs);
}
}
//
// Otherwise, display a system error.
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
An error occured converting your code, probably due to a syntax error:
-- line 10 col 1: EOF expected
TommySzalapski
Keep in mind that some people consider it a security vulnerability to respond to that type of ping request so there are not many tools that work with it and you might have to change some configurations to get the remote machine to actually respond. http://capec.mitre.org/data/definitions/295.html
hping and nping are both open source tools that will send ICMP timestamp requests. I don't think there is any built in way to do it from the command prompt.
TommySzalapski
Which line is line 10?
Just use main, and char instead of wmain and wchar_t....
Imports System.Net.NetworkInformat
Imports System.Net.NetworkInformat
Imports System.Net.NetworkInformat
These three lines are in the declarations section.
' Ping
Dim PingReturn As System.Net.NetworkInformat
Dim sReturn As System.Net.NetworkInformat
Dim TimeReturn As System.Net.NetworkInformat