Sign in to follow this  
Followers 0
SetEnv

Problem in 'network-related' Function

11 posts in this topic

Hello!

First of all: I'm sorry about my verry bad english...

Now...

I tried to write a simple function to get the abuse email related to an IP.

The code is not working, and I don't know why...

In fact: you can telnet 'whois.ripe.net 43' and ask for whois any ip/address you want. Then, you will receive the answer containing all the infos...

Here's the not-working-code ...

GetProviderMail()

Func GetProviderMail()
    $gSocket = TCPConnect("whois.ripe.net", "43")
    
    If $gSocket <> -1 Then ; If no error then
        TCPSend($gSocket, "4.2.2.4") ; ask about 4.2.2.4 (for example)
        
        $gSocket = -1
            
        Do
            $gSocket = TCPAccept($gSocket)
        Until $gSocket <> -1
        
        $gData = TCPRecv($gSocket,2048)
        
        $gDataSplit = StringSplit($gData,":")
        If $gDataSplit[1] == "e-mail" Then TrayTip("server","AbuseEmail for '4.2.2.4' is:"& $gDataSplit[2],5,2)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites



to get you started:

GetProviderMail()
Func GetProviderMail()
    $gData = ""
    TCPStartup()
    $gSocket = TCPConnect(TCPNameToIP("whois.ripe.net"), 43)
    If $gSocket <> -1 Then; If no error then
        TCPSend($gSocket, "4.2.2.4"); ask about 4.2.2.4 (for example)
        sleep(500)
        $gData &= TCPRecv($gSocket, 2048)
        ConsoleWrite('$gData = ' & $gData & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
    EndIf
    TCPShutdown()
EndFunc  ;==>GetProviderMail

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Oh... i'm so noobish.

Thanks! :-s

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It seems I can't receive all the response... I just read the 'first' block

I'm using a while to re-read the datas, but apparently, that's not working.

Could you tell me where i'm wrong? Thanks

eg:

% Some informations

% here about ripe.net

% ...

% http://www.ripe.net

<

here should

come the informations

about the requested ip

>

The code:

GetProviderMail()

Func GetProviderMail()
    $gData = ""
    TCPStartup()
    $gSocket = TCPConnect(TCPNameToIP("whois.ripe.net"), 43)
    If $gSocket <> -1 Then; If no error then
        
        TCPSend($gSocket, "4.2.2.4"); ask about 4.2.2.4 (for example)

        sleep(500)
        
        While 1
            $gData = TCPRecv($gSocket, 2048)
            
            If $gData == -1 Then 
                ExitLoop 
            Else
                $gSplit = StringSplit($gData,":") ; split data
            
                For $gVar = $gSplit[0] To 1 Step -1 
                    Debug($gSplit[$gVar]) ;### Debug TrayTip
                Next
            EndIf
        WEnd
    EndIf
    TCPShutdown()
EndFunc  ;==>GetProviderMail

Func Debug($dbg)
    TrayTip("DEBUG:",$dbg,3, 1)
    Sleep(3100)
EndFunc  ;==>Debug
Edited by SetEnv

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try mine, I did this some days ago.

TCPStartUp()
$Domain = TCPNameToIP("whois.ripe.net");whois.arin.net  whois.internic.net  whois.ripe.net
$Port = 43
$Address = '4.2.2.4'

Global $recv

$socket = TCPConnect($Domain, $Port)

If $socket <> -1 Then
   TCPSend($socket, $Address & @CRLF)
   
    Do
        $recv &= TCPRecv($socket, 2048) 
    Until @error
   ConsoleWrite($recv)
   TCPCloseSocket($socket)
   
EndIf
TCPShutdown()
Edited by Pain

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yup,

Your code seems work perfectly !

But (yeah...) the datas are not totally received :-s

Your code with little modifications:

GetAbuseEmail()

Func GetAbuseEmail()

    TCPStartUp()
    $Domain = TCPNameToIP("whois.ripe.net");whois.arin.net  whois.internic.net  whois.ripe.net
    $Port = 43
    $Address = '-B 4.2.2.4' ; flag -B used to force 'update' (whois.ripe.net args)

    Global $recv

    $socket = TCPConnect($Domain, $Port)

    If $socket <> -1 Then
    TCPSend($socket, $Address & @CRLF)
  
        Do
            $recv &= TCPRecv($socket, 2048)
        Until @error
    
    TrayTip("debug", $recv, 4, 1)
    Sleep(2000)
    TCPCloseSocket($socket)
  
    EndIf
    TCPShutdown()
EndFunc ;==> GetAbuseEmail
Edited by SetEnv

Share this post


Link to post
Share on other sites

Sorry Pain, your code is perfect !

It's just that traytip(title, string, time,type) seems bug if the char '"' is in the string.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

It works just fine for me.

TrayTip("", 'A "traytip"', 4, 1)

Sleep(5000)

Edited by Pain

Share this post


Link to post
Share on other sites

Yeah but,

Traytip("test", "test "test", 3, 3) Will not work, and it's normal...

And, in whois.ripe.net response, there was some '"' or "'"

That's why when i tryied to traytip() thoses chains containing '"' or "'" , I saw nothing.

Now, without traytip(), the code woks perfectly and I can extract the email adress

That's why I think Traytip() is bugged =)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

It's not bugged, from the helpfile

Message the balloon tip will display. (255 characters maximum)

Try with ConsoleWrite(StringLen($recv)), I got 1934 so that might be the reason why. :)

TCPStartUp()
$Domain = TCPNameToIP("whois.ripe.net");whois.arin.net  whois.internic.net  whois.ripe.net
$Port = 43
$Address = '-B 4.2.2.4'

Global $recv

$socket = TCPConnect($Domain, $Port)

If $socket <> -1 Then
   TCPSend($socket, $Address & @CRLF)
   
    Do
        $recv &= TCPRecv($socket, 2048) 
    Until @error
;~  ConsoleWrite($recv)
    TrayTip("",StringLeft($recv, 255), 4, 1)
    Sleep(2000)
   TCPCloseSocket($socket)
   
EndIf
TCPShutdown()
Edited by Pain

Share this post


Link to post
Share on other sites

grmbl.. Ok =)

I dind't RTFM :-/

Share this post


Link to post
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
Sign in to follow this  
Followers 0