Sign in to follow this  
Followers 0
Shyke

_GetSMTP()

6 posts in this topic

#1 ·  Posted (edited)

;===============================================================================
;
; Function Name:    _GetSMTP()
; Description:    Gets ISP issued SMTP server.
; Parameter(s):  None
; Requirement(s):   Internet access.
; Return Value(s):  On Success - Returns SMTP Server
;                  On Failure - Unknown
; Author(s):        Shyke
; Note:          Only works with normal lan or directly connected PCs,
;                  doesn't return the proper SMTP server in some cases.
;
;===============================================================================

Func _GetSMTP()
    Local $s_SMTP
    Run(@ComSpec & " /c nslookup > " & @TempDir & "~tt.tmp", "", @SW_HIDE)
    Sleep(2000)
    $s_SMTP = FileReadLine(@TempDir & "~tt.tmp", 1)
    $s_SMTP = StringTrimLeft($s_SMTP, 17)
    $s_SMTP = StringSplit($s_SMTP, ".")
    ProcessClose("cmd.exe")
    ProcessClose("nslookup.exe")
    FileDelete(@TempDir & "~tt.tmp")
    Return "smtp." & $s_SMTP[$s_SMTP[0] - 1] & "." & $s_SMTP[$s_SMTP[0]]
EndFunc

What do you guys think?

If anyone sees any improvements, I'm greatly requesting that you add them.

Edited by Shyke

Share this post


Link to post
Share on other sites



i don't understand how this script would get the smtp server? its a cool idea tho

reading thru it it calls nslookup then writes the result to a file... this would return the default DNS server for the computer would it not?

Share this post


Link to post
Share on other sites

i don't understand how this script would get the smtp server? its a cool idea tho

reading thru it it calls nslookup then writes the result to a file... this would return the default DNS server for the computer would it not?

Exactly! This just gets the DNS server, and not the SMTP server.

It may be that in some cases it is all the same, but I doubt it.

Share this post


Link to post
Share on other sites

Could shorten the function a bit as well :whistle:

Func _GetDNS()
    Local $aSRE = StringRegExp(StdoutRead(Run(@ComSpec & " /c nslookup", "", @SW_HIDE, 2)), '(?s)(?i)Default Server:  .*?\.(.*?)(?m:$|\r)', 1)
    If IsArray($aSRE) Then Return $aSRE[0]
    Return SetError(1, 0, '')
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hi,

this way it will work for every language:

MsgBox(0,"",_GetDNS())

Func _GetDNS()
    Local $aSRE = StringRegExp(StdoutRead(Run(@ComSpec & " /c nslookup", "", @SW_HIDE, 2)), '(?s)(?i)server:  .*?\.(.*?)(?m:$|\r)', 1)
    If IsArray($aSRE) Then Return $aSRE[0]
    Return SetError(1, 0, '')
EndFunc

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi,

this way it will work for every language:

So long,

Mega

Unless the language does not know the word Server...

MsgBox(0,"",_GetDNS())

Func _GetDNS()
    Local $aSRE = StringRegExp(StdoutRead(Run(@ComSpec & " /c nslookup", "", @SW_HIDE, 2)), '.*?\.(.*?)(?m:$|\r)', 1)
    If IsArray($aSRE) Then Return $aSRE[0]
    Return SetError(1, 0, '')
EndFunc
Edited by Manadar

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