Jump to content

TCPNameToIP


Recommended Posts

$Real_Ip = @IPAddress1

or

$Real_Ip = TCPNameToIP ($server)

 

Hi, I have a question if someone can help me.

I have seen many examples on this forum, What is $server in the case ?

Why should contain?

 

can someone show me an example link?

Thanks.

Link to comment
Share on other sites

It should contain the domain name e.g. google.com or autoitscript.com and then that will contact your dns server to resolve to an ip address.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

What about _TCPIpToName? Or could you explain a little clearer. Thanks.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

 client:

#include <Array.au3>
#Include <String.au3>

TCPStartup()

Global $SERVER, $SOCKET[1] = [""], $NICKS[1] = [""]

$SERVER = TCPListen(@IPAddress1,1337)
If @error Then
    MsgBox(0,"error","Error listening on port 1337.")
    Quit()
EndIf

While 1
    sleep(25)

    $TConn = TCPAccept($SERVER)

    If $TConn <> -1 Then
        _ArrayAdd($SOCKET,$TConn)
        _ArrayAdd($NICKS,"guest")
    EndIf

    recvAll()

WEnd

Func recvAll()
    Local $RECV, $cmd, $text

    For $Cx = 0 to UBound($SOCKET) - 1

        $RECV = ""
        $curLine = ""

        If $SOCKET[$Cx] <> "" Then

            $RECV = TCPRecv($SOCKET[$Cx], 512)
            If StringLen($RECV) > 7 Then

                $RECV = StringSplit($RECV, @CRLF)

                For $curLine In $RECV

                    $cmd = StringLeft($curLine, 7)
                    $text = StringMid($curLine, 8)

                    Switch $cmd
                    Case "CONNECT"
                        $NICKS[$Cx] = StringReplace($text,"|","_")
                        notifyAll("New user " & $text & " has connected.")
                        sendAllNicks()
                    Case "NICKNAM"
                        changeNick($Cx,$text)
                    Case "DISCONN"
                        notifyAll("User " & $NICKS[$Cx] & " has disconnected.")
                        _ArrayDelete($SOCKET,$Cx)
                        _ArrayDelete($NICKS,$Cx)
                    Case "CHATMSG"
                        chatAll($Cx,$text)
                    Case "USERMSG"
                        chatUser($Cx,$text)
                    Case "NICKLST"
                        sendNicks($SOCKET[$Cx])
                    EndSwitch

                Next

            EndIf
        EndIf
    Next
EndFunc

Func sendAllNicks()
    For $user In $SOCKET
        If $user <> "" Then
                sendNicks($user)
        EndIf
    Next
EndFunc

Func sendNicks($user)
        TCPSend($user, "NICKLST" & _ArrayToString($NICKS) & @CRLF)
EndFunc

Func changeNick($userNum,$newNick)
    $newNick = StringReplace($newNick,"|","_")
    If StringLen($newNick) >= 3 Then
        If $NICKS[$userNum] <> $newNick Then
            If _ArraySearch($NICKS,$newNick) == -1 Then
                notifyAll("User " & $NICKS[$userNum] & " is now known as " & $newNick)
                setNick($userNum,$newNick)
                sendAllNicks()
            Else
                notifyUser($SOCKET[$userNum],"Nickname " & $newNick & " is already in use!")
                setNick($userNum, $NICKS[$userNum])
            EndIf
        EndIf
    Else
        notifyUser($SOCKET[$userNum],"Nickname " & $newNick & " is too short. Must be at least 3 characters.")
        setNick($userNum, $NICKS[$userNum])
    EndIf
EndFunc

Func setNick($user, $nick)
    $NICKS[$user] = $nick
    TCPSend($SOCKET[$user], "NICKNAM" & $nick & @CRLF)
EndFunc

Func notifyUser($socket, $msg)
        TCPSend($socket, "NOTIFYM" & $msg & @CRLF)
EndFunc

Func notifyAll($msg)
    For $user In $SOCKET
        If $user <> "" Then
            notifyUser($user, $msg)
        EndIf
    Next
EndFunc

Func chatAll($from,$msg)
    If $msg <> "" Then
        For $Ox = 0 to UBound($SOCKET) - 1
            If $SOCKET[$Ox] <> "" Then
                If TCPSend($SOCKET[$Ox], "CHATMSG" & $NICKS[$from] & "|" & $msg & @CRLF) == 0 And @error Then
                    TCPCloseSocket($SOCKET[$Ox])
                    _ArrayDelete($SOCKET,$Ox)
                    _ArrayDelete($NICKS,$Ox)
                EndIf
            EndIf
        Next
    EndIf
EndFunc

Func chatUser($from,$msg)

    Local $to,$text

    $to = _StringBetween($msg, "", "|")
    $text = _StringBetween($msg, "|", "")

    If $msg <> "" Then
        $userID = _ArraySearch($NICKS,$to[0])
        If $userID <> -1 Then
            If TCPSend($SOCKET[$userID], "USERMSG" & $NICKS[$from] & "|" & $text[0] & @CRLF) == 0 And @error Then
                TCPCloseSocket($SOCKET[$userID])
                _ArrayDelete($SOCKET,$userID)
                _ArrayDelete($NICKS,$userID)
            EndIf
        Else
            notifyUser($SOCKET[$from], "Nickname " & $to[0] & " is not online.")
        EndIf
    EndIf
EndFunc

Func Quit()
    For $Qx = 0 to UBound($SOCKET) - 1
        notifyUser($SOCKET[$Qx], "Server is shutting down...")
        TCPCloseSocket($SOCKET[$Qx])
    Next
    TCPShutdown()
    Exit
EndFunc

Server:

#Include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Misc.au3>
#include <String.au3>


Global $username
Global Const $winTitle = "Server"
TCPStartup()

Global $CONNECT = 0, $NICKLIST = ""


GUICreate($winTitle, 500, 500)
GUISetState()

Global $btnConnect = GUICtrlCreateButton("Connect", 10, 10, 100, 30)

Global $info = GUICtrlCreateEdit("", 10, 50, 325, 350, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL), $WS_EX_STATICEDGE)
GUICtrlSetBkColor(-1, 0xFFFFFF)

Global $edtNicklist = GUICtrlCreateEdit("",340, 50, 150, 350, $ES_READONLY)

Global $sending = GUICtrlCreateInput("", 10, 410, 400, 70)
Global $b_send = GUICtrlCreateButton("Send", 420, 410, 70, 70, BitOR($BS_DEFPUSHBUTTON, $WS_GROUP))


While True

    $RECV = ""

    If $CONNECT <> 0 Then

        $RECV = TCPRecv($CONNECT,512)
        If @error Then destroyConnect()

        If StringLen($RECV) > 7 Then

            $RECV = StringSplit($RECV, @CRLF)

            For $curLine In $RECV

                $cmd = StringLeft($curLine, 7)
                $text = StringMid($curLine, 8)

                Switch $cmd
                Case "NOTIFYM"
                    displayNotify($text)
                Case "CHATMSG"
                    displayChat($text)
                Case "NICKLST"
                    updateNicks($text)
                Case "USERMSG"
                    displayUserMsg($text)
                Case "NICKNAM"
                    $username = $text
                EndSwitch
            Next

        EndIf
    EndIf

    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        Quit()
    Case $b_send
        say()
    Case $btnConnect
        toggleConnect()
    EndSwitch


WEnd

Func updateNicks($text)

        GUICtrlSetData($edtNicklist, StringReplace($text, "|", @CRLF))

EndFunc

Func toggleConnect()
    If TCPSend($CONNECT, "ping" & @CRLF) Then
        destroyConnect()
    Else
        initConnect()
    EndIf
EndFunc

Func initConnect()

    If StringLen($username) < 3 Then
            $username= InputBox("Username", "What would you like your username to be?")
    EndIf

    displayNotify("Connecting to server...")

    $CONNECT = TCPConnect(@IPAddress1 ,1337)
    If @error Then
            displayNotify("Unable to connect")
            GUICtrlSetData($btnConnect, "Connect")
            Return
    EndIf

    TCPSend($CONNECT, "CONNECT" & $username & @CRLF)

    displayNotify("Connected!")
    GUICtrlSetData($btnConnect, "Disconnect")

EndFunc

Func destroyConnect()

    TCPSend($CONNECT, "DISCONN" & @CRLF)
    TCPCloseSocket($CONNECT)
    $CONNECT = 0
    displayNotify("You have disconnected.")
    GUICtrlSetData($btnConnect, "Connect")
    GUICtrlSetData($edtNickList, "")

EndFunc

Func displayNotify($text)
        GUICtrlSetData($info, "*** " & $text & " ***" & @CRLF, True)
EndFunc

Func displayChat($text)

    Local $nick, $msg

    $nick = _StringBetween($text, "", "|")
    $msg = _StringBetween($text, "|", "")

    If $nick[0] == $username Then
            $nick[0] = "* " & $nick[0]
    EndIf

    GUICtrlSetData($info, timestamp() & $nick[0] & ": " & $msg[0] & @CRLF, True)

EndFunc

Func displayUserMsg($text)

    Local $nick, $msg

    $nick = _StringBetween($text, "", "|")
    $msg = _StringBetween($text, "|", "")

    GUICtrlSetData($info, "** From " & $nick[0] & ": " & $msg[0] & @CRLF, True)
EndFunc

Func timestamp()

    Local $timestamp

    $timestamp = "[hh:mm:ss] "
    $timestamp = StringReplace($timestamp, "hh", @HOUR)
    $timestamp = StringReplace($timestamp, "mm", @MIN)
    $timestamp = StringReplace($timestamp, "ss", @SEC)

    Return $timestamp

EndFunc

Func say()
    $DATA = GUICtrlRead($Sending)
    If $DATA <> "" Then
        If StringLeft($DATA,6) == "/nick " And StringLen($DATA) > 8 Then
            TCPSend($CONNECT, "NICKNAM" & StringMid($DATA,7) & @CRLF)
        ElseIf StringLeft($DATA,5) == "/msg " And StringLen($DATA) > 9 Then
            $DATA = StringTrimLeft($DATA,5)
            $toNick = _StringBetween($DATA, "", " ")
            $toMsg = _StringBetween($DATA, " ", "")
            TCPSend($CONNECT, "USERMSG" & $toNick[0] & "|" & $toMsg[0] & @CRLF)
            GUICtrlSetData($info, "** To " & $toNick[0] & ": " & $toMsg[0] & @CRLF, True)
        Else
            TCPSend($CONNECT, "CHATMSG" & $DATA & @CRLF)
        EndIf
        GUICtrlSetData($sending, "")
    EndIf
EndFunc

Func Quit()
    destroyConnect()
    sleep(50)
    TCPShutdown()
    Exit
EndFunc

I have this script chat
I'm not real computer IP, therefore I can not use the external program than in Local, is there any way to use the program everywhere, without the real ip?

I was thinking that is another alternative using this function TCPNameToIP

Thank you!

Edited by incepator
Link to comment
Share on other sites

@IPAddress# will return the LAN IP address of the computer, you need the external IP address which can be gotten using _GetIP which is a function that guiness wrote and a link can be found in his signature. Then you need to forward the port, that the server is using, to the correct computer in your router set up.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Yeh, the version BrewManNH mentions is a lot more stable than the currently released 'stable' version as part of v3.3.8.1.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...