Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Function to get highlighted text from the clipboard
- GetHighlightedText() {
- ClipSaved := ClipboardAll ; Save the current clipboard content
- Clipboard := "" ; Clear the clipboard
- Send, ^c ; Copy the selected text
- ClipWait, 1 ; Wait for the clipboard to contain text
- text := Clipboard ; Store the copied text
- ; Check if text is empty
- if (text = "") {
- MsgBox, No text selected! Please copy again.
- Clipboard := ClipSaved ; Restore the original clipboard
- return ; Exit the function
- }
- text := Trim(text) ; Trim whitespace from the text
- Clipboard := ClipSaved ; Restore the original clipboard
- return text ; Return the highlighted text
- }
- ; Function to resolve hostname to IP address
- ResolveHostname(hostname) {
- hWS2_32 := DllCall("LoadLibrary", "str", "ws2_32.dll", "ptr")
- VarSetCapacity(WSADATA, 394 + (A_PtrSize - 2) + A_PtrSize, 0)
- if (DllCall("ws2_32\WSAStartup", "ushort", 0x0202, "ptr", &WSADATA) != 0) {
- DllCall("ws2_32\WSACleanup")
- return "Failure in WSAStartup"
- }
- VarSetCapacity(hints, 16 + 4 * A_PtrSize, 0)
- NumPut(2, hints, 4, "int") ; AF_INET
- NumPut(1, hints, 8, "int") ; SOCK_STREAM
- NumPut(6, hints, 12, "int") ; IPPROTO_TCP
- result := 0
- if (DllCall("ws2_32\getaddrinfo", "astr", hostname, "ptr", 0, "ptr", &hints, "ptr*", result)) {
- DllCall("ws2_32\WSACleanup")
- return "getaddrinfo: " DllCall("ws2_32\WSAGetLastError")
- }
- addr := result
- IPList := []
- while (addr) {
- ipaddr := DllCall("ws2_32\inet_ntoa", "uint", NumGet(NumGet(addr + 0, 16 + 2 * A_PtrSize) + 4, 0, "uint"), "astr")
- IPList.Push(ipaddr)
- addr := NumGet(addr + 0, 16 + 3 * A_PtrSize)
- }
- DllCall("ws2_32\WSACleanup")
- DllCall("FreeLibrary", "ptr", hWS2_32)
- return IPList
- }
- ; Function to show IP addresses in a GUI
- ShowIPAddresses(IPAddresses) {
- Gui, New, +AlwaysOnTop +ToolWindow +Resize
- Gui, Add, Text, vIPText, Resolved IP Addresses:`n
- for index, ip in IPAddresses {
- GuiControl,, IPText, % ip "`n" ; Append each IP address to the GUI text
- }
- Gui, Show, AutoSize, IP Addresses
- ; Position the GUI near the mouse cursor
- MouseGetPos, mouseX, mouseY
- Gui, Show, x%mouseX% y%mouseY% ; Show GUI near mouse position
- }
- ; Hotkey to trigger the action when F8 is pressed
- F8::
- highlightedText := GetHighlightedText() ; Get the highlighted text
- if (highlightedText) {
- IPAddresses := ResolveHostname(highlightedText) ; Resolve the hostname to IP addresses
- if (IsObject(IPAddresses)) {
- ShowIPAddresses(IPAddresses) ; Show IP addresses in a GUI
- } else {
- MsgBox % "Error: " IPAddresses ; Display error message if any
- }
- }
- return
Advertisement
Add Comment
Please, Sign In to add comment