Datum abfragen / Lizenzschlüssel Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

tm6464
Posts: 48
Joined: 17 Jul 2017, 22:56

Re: Datum abfragen / Lizenzschlüssel

22 Jul 2017, 03:11

habe jetzt mal das zusammengebastelt , bin ahk anfänger aber es funktioniert :D

Code: Select all

ie := ComObjCreate("InternetExplorer.Application")
ie.Navigate("http://time.utoo.de/time.html")
While (ie.busy || or ie.Readystate <> 4)
	Sleep 100
msgbox % ie.document.body.innerText 
v_current_date := % ie.document.body.innerText
ie.quit

FormatTime, v_max_date, %max_date%, yyyyMMdd 
			v_max_date := "2017615"
			If (v_current_date >= v_max_date) {
			MsgBox, 0, , Der Lizenzschlüssel Ihres Produktes ist abgelaufen., 5
				return
			}
			MsgBox, 0, , Der Lizenzschlüssel Ihres Produktes ist gültig., 5
auf der website

Code: Select all

<script type="text/javascript">
document.write(new Date().getFullYear()+""+(new Date().getMonth()+1)+""+new Date().getDate())
</script>
leider zeigt es bei monat keine 0 an zb bei Juli "07"
vll weisst du wie man das in java oder php macht ...
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Datum abfragen / Lizenzschlüssel

22 Jul 2017, 03:36

tm6464 wrote:habe jetzt mal das zusammengebastelt , bin ahk anfänger aber es funktioniert :D

[...]

leider zeigt es bei monat keine 0 an zb bei Juli "07"
vll weisst du wie man das in java oder php macht ...
Nachträglich aufnullen kannst du auch mit SetFormat oder Format().
Last edited by BoBo on 22 Jul 2017, 03:51, edited 2 times in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Datum abfragen / Lizenzschlüssel

22 Jul 2017, 03:40

Vll kann einer der cracks mal die bsp hier sichten und in AHK übersetzen?! Solution 3 ..??
https://www.codeproject.com/Questions/3 ... m-internet
oder die Google URL nach dessen zeit abfragen?
https://dotnet-snippets.de/snippet/datu ... holen/1683

:)
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Datum abfragen / Lizenzschlüssel

22 Jul 2017, 08:43

Moin,

ich habe hier etwas gefunden und mit Hilfe von Bentschis Socket Skripten nach AHK übersetzt:

Code: Select all

MsgBox, % GetNetworkTime()

GetNetworkTime(Server := "", Port := "") {
   ; stackoverflow.com/questions/1193955/how-to-query-an-ntp-server-using-c
   Static NtpServer := "time.windows.com"
        , NtpPort := 123
   ; -----------------------------------------------------------------------------------------------------------------------------
   If (Server = "")
      Server := NtpServer
   If (Port = "")
      Port := NtpPort
   ; -----------------------------------------------------------------------------------------------------------------------------
   Ws2 := DllCall("LoadLibrary", "Str", "Ws2_32.dll")
   If !(Ws2) {
      Msg := "WS2_32.dll could not be loaded!"
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Initialize the winsock library
   VarSetCapacity(WsaData, 512, 0) ; more than sufficient
   If (DllCall("Ws2_32\WSAStartup", "UShort", 0x0202, "UInt", &WsaData) <> 0) { ; Request Winsock 2.2
      Msg := "WSAStartup() could not be called due to error " . A_LastError . " - " . ErrorLevel
              . "`nWinsock 2.2 or higher is required."
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Name resolution
   If !(HOSTENT := DllCall("Ws2_32.dll\gethostbyname", "AStr", Server, "UPtr")) {
      Msg := "gethostbyname failed with error " . DllCall("Ws2_32.dll\WSAGetLastError", "Int")
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   PAddrList := NumGet(HOSTENT + 0, (2 * A_PtrSize) + 4 + (A_PtrSize - 4), "UPtr")
   PIPAddr   := NumGet(PAddrList + 0, 0, "UPtr")
   Addr := StrGet(DllCall("Ws2_32.dll\inet_ntoa", "UInt", NumGet(PIPAddr + 0, 0, "UInt"), "UPtr"), "CP0")
   InetAddr := DllCall("Ws2_32.dll\inet_addr", "AStr", Addr, "UInt") ; convert address to 32-bit UInt
   If (InetAddr = 0xFFFFFFFF) {
      Msg := "inet_addr failed for address " . Addr
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Create a socket: AF_INET = 2, SOCK_DGRAM =  2, IPPROTO_UDP = 17
   Socket := DllCall("Ws2_32\socket", "UInt", 2, "UInt", 2, "UInt", 17, "Int")
   If (Socket = -1) { ; INVALID_SOCKET = -1
      Msg := "socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Connect to the socket
   SocketAddrSize := 16
   VarSetCapacity(SocketAddr, SocketAddrSize, 0)
   VarSetCapacity(SocketAddr, SocketAddrSize, 0)
   NumPut(2, SocketAddr, 0, "Short") ; sin_family = AF_INET
   NumPut(DllCall("Ws2_32\htons", "UShort", Port), SocketAddr, 2, "UShort") ; sin_port
   Numput(InetAddr, SocketAddr, 4, "UInt") ; sin_addr.s_addr
   ; Attempt connection
   If DllCall("Ws2_32\connect", "UInt", Socket, "UInt", &SocketAddr, "Int", SocketAddrSize) {
      Msg := "connect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Send an NTP request
   SocketError := -1
   VarSetCapacity(Data, 48, 0)
   NumPut(0x1B, Data, "UChar") ; LI = 0 (no warning), VN = 3 (IPv4 only), Mode = 3 (Client Mode)
   SendRet := DllCall("Ws2_32\send", "UInt", Socket, "Str", Data, "Int", 48, "Int", 0, "Int")
   If (SendRet = SocketError) {
      Msg := "send() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Shutdown sending
   DllCall("Ws2_32\shutdown", "UInt", Socket, "Int", 1) ; SD_SEND = 1
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Get the answer
   RecvRet := DllCall("Ws2_32\recv", "UInt", Socket, "Ptr", &Data, "Int", 48, "Int", 0, "Int")
   If (RecvRet = SocketError) {
      Msg := "recv() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
      Return GetNetworkTime_Error(Msg, Ws2)
   }
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Free resources
   DllCall("Ws2_32\closesocket", "UInt", Socket)
   DllCall("Ws2_32.dll\WSACleanup") ; Terminate the use of the Winsock 2 DLL
   DllCall("FreeLibrary", "Ptr", Ws2)
   ; -----------------------------------------------------------------------------------------------------------------------------
   ; Swap byte order
   Sek := (NumGet(Data, 40, "Uchar") << 24) | (NumGet(Data, 41, "Uchar") << 16) | (NumGet(Data, 42, "Uchar") << 8)
         | NumGet(Data, 43, "Uchar")
   DT := "19000101"
   DT += Sek, S
   Return DT
}

GetNetworkTime_Error(Msg, HMOD, RetVal := 0) {
   MsgBox, 0, %A_ThisFunc%, %Msg%
   DllCall("Ws2_32.dll\WSACleanup") ; Terminate the use of the Winsock 2 DLL
   DllCall("FreeLibrary", "Ptr", HMOD)
   Return RetVal
}
Ich habe das nur gegen den Microsoft Server getestet. Damit läuft es hier.

Achtung: Die zurückgegebene Zeit ist UTC!
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Datum abfragen / Lizenzschlüssel

23 Jul 2017, 10:40

just me wrote:Moin,

ich habe hier etwas gefunden und mit Hilfe von Bentschis [...] gegen den Microsoft Server getestet. Damit läuft es hier.

Achtung: Die zurückgegebene Zeit ist UTC!
Merci vielmals. Matsch ebrieschieededh :thumbup:
Werde mal schaun ob sich dazu evtl noch ein MESZ/CEST conversions script (für die nachfolgenden) daten findet ...
Gefunden. Das ergebnis wäre nun als indikator zum 'aufrunden' des UTC zu MESZ/CEST zu verwenden.

Code: Select all

#SingleInstance, Force

/*

time := GetNetworkTime()															; Abfrage der zeit via internet (Ausgabe im UTC format) ... https://autohotkey.com/boards/viewtopic.php?p=160975#p160975 by 'just me'
res  := DateBetween(GetNetworkTime(),20170326,20171029)								; Abgleich ob retournierte zeit noch innerhalb des zeitraum für die MESZ/CEST liegt
dst  := (res = 0) ?  1 : 2															; Berechnen des 'ab-/zuschlags' MEZ/CET vs MESZ/CEST
	time  += dst, Hours
MsgBox % time

*/

MsgBox, % DateBetween(A_Now,20170326,20171029)										; Ermitteln ob die aktuelle systemzeit ... (1 = true, 0 = false)
MsgBox, % DateBetween(20171001,20170326,20171029) = 0 ? "MEZ/CET" : "MESZ/CEST"		; Ermitteln ob der 01.10.2017 ... (Ergebnis "MESZ/CEST" da datum innerhalb der sommerzeit liegt)
MsgBox, % DateBetween(20171101,20170326,20171029) = 0 ? "MEZ/CET" : "MESZ/CEST"		; Ermitteln ob der 01.11.2017 ... (Ergebnis "MEZ/CET" da datum ausserhalb der sommerzeit liegt)

/*
	MESZ/CEST
	von			bis
	26.03.2017	29.10.2017
	25.03.2018	28.10.2018
	31.03.2019	27.10.2019
	29.03.2020	25.10.2020
	28.03.2021	31.10.2021
	27.03.2022	30.10.2022
	26.03.2023	29.10.2023
	31.03.2024	27.10.2024
	30.03.2025	26.10.2025
	29.03.2026	25.10.2026
	28.03.2027	31.10.2027
	26.03.2028	29.10.2028
*/

DateBetween(Date,Low,High="A_Now"){			; https://autohotkey.com/board/topic/70962-need-program-to-determine-if-date-is-in-a-certain-range/ by [VXE]nli
	If High is not Digit					; Returns 1 if date is in range, 0 if not
		High = A_Now
	High -= Date, s 
	If Low Is Not Digit
		Return 0 <= High
	Low -= Date, s 
	Return 0 <= High && Low <= 0
	}
:)
Last edited by BoBo on 24 Jul 2017, 02:51, edited 2 times in total.
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Datum abfragen / Lizenzschlüssel

24 Jul 2017, 02:44

Moin BoBo,

ich habe die Funktion etwas überarbeitet und hier eingestellt. Funktionen zur Behandlung von UTC-Zeiten habe ich dazugepackt.

Endscheu juhrßelf! ;)

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 110 guests