Old 12th May 2005, 14:19   #1
PleaseKING
Junior Member
 
Join Date: May 2005
Location: St.Petersburg, Russia
Posts: 3
Send a message via ICQ to PleaseKING Send a message via Yahoo to PleaseKING
Test connection to specific address/port

Hello all,

I am creating an installer with NSIS, and I would like to validate the SMTP server name user enters by connecting to port 25 of this server. This is fully automatic and gives some guarantee that the SMTP server is entered correctly. Is there any way to try to connect to specific IP address/port from NSIS?
PleaseKING is offline   Reply With Quote
Old 12th May 2005, 16:39   #2
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
There is IPDll and you can try to use it. But I don't know about working with specific port. Try.
glory_man is offline   Reply With Quote
Old 12th May 2005, 17:01   #3
PleaseKING
Junior Member
 
Join Date: May 2005
Location: St.Petersburg, Russia
Posts: 3
Send a message via ICQ to PleaseKING Send a message via Yahoo to PleaseKING
As far as I understand, IPDll is a thing to test IP addresses statically, just basing on some fixed rules, not trying to connect physically. But maybe I am wrong.
PleaseKING is offline   Reply With Quote
Old 16th June 2005, 13:05   #4
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
Working with sockets

Hello
This function connect a socket to a ServerIP and Port and disconect this.
Useful if you want to know if a server service is running in a port.
Tested with windowsXp and Win98.


push "ServerIP"
push "PortToConect"
Call SocketToServerAndPort
pop $R0

At this moment $R0 is 0 (conect to socket OK) or -1 (conect to socket not OK)
note : Socket Version Dll required 2.2 . If you want to change the version, change on WSAStartup function.

Examples

Section "mysql" mysql
push "127.0.0.1"
push "3306"
Call SocketToServerAndPort
pop $R0
messagebox mb_ok "Mysql : return $R0"
SectionEnd

Section "web" web
push "127.0.0.1"
push "80"
Call SocketToServerAndPort
pop $R0
messagebox mb_ok "Web : return $R0"
SectionEnd

Section "smtp" smtp
push "127.0.0.1"
push "25"
Call SocketToServerAndPort
pop $R0
messagebox mb_ok "Smtp : return $R0"
SectionEnd

PHP Code:
Function SocketToServerAndPort

Exch 
$PortToConect
Exch
Exch 
$ServeIP
Push 
$address struct wsadata
Push 
$WSAStartup return
Push $socket return
Push $ntohs return
Push $inet_addr
Push 
$addres struct sockaddr_in
Push 
$connect return ¡¡
push 
$WSACleanup return
push $R0 
push $R1 ;  Temp
push $R2 
;   "
push 
$R3 ;  wVersion
push 
$R4 ; szDescription
push 
$R5 ; wHighVersion
push 
$R6 ; szSystemStatus
push 
$R7 ; iMaxSockets
push 
$R8 ; iMaxUdpDg
push 
$R9 ; lpVendorInfo


!define struct_wsadata  '(&i2,&i2,&t257,&t129,i,i,l)i'
System::Call '*
${struct_wsadata} .r2' ; allocates memory for wsadata struct and writes address to $2
        ; 514 =2 + 256*2 = MAKEWORD (bLow,bHigh) = bLow + 256 * bHigh ==> version socket
        ; note : Socket Version Dll required 2.2 or higher
System::Call 'ws2_32::WSAStartup(i 514 ,i r2)i .r3'
IntCmp 0 $3 0 DllNotOK DllNotOK
       System::Call '*$2
${struct_wsadata}(.R3,.R4,.R5,.R6,.R7,.R8,.R9)'
       IntOp 
$R3 $R3 / 256
       IntOp 
$R1 $3 % 256
       IntOp 
$R4 $R4 % 256
       IntOp 
$R2 $R4 % 256
       ; From winsock.h :
       ; AF_INET                 = 2
       ; IPPROTO_TCP             = 6
       ; SOCK_STREAM             = 1
System::Call 'ws2_32::socket(i 2,i 1,i 6)i .r4'

System::Call 'ws2_32::ntohs(i $0) i.r5'
System::Call 'ws2_32::inet_addr(t "
$1") i.r6'

!define struct_sockaddr_in  '(&i2,&i2,&i4,&t8)i'
System::Call '*
${struct_sockaddr_in} .r7' ; allocates memory for sockaddr_in struct and writes address to $7
System::Call '*$7
${struct_sockaddr_in}(2,r5,r6,)' ;

System::Call 'ws2_32::connect(i $4,i $7,i 16) i.r8'

System::Call 'ws2_32::WSACleanup()i .r9 '

;DetailPrint "
***********************"
;DetailPrint "
Port = $0"
;DetailPrint "
Server = $1"
;DetailPrint "
Version $R3.$R1"
;DetailPrint "
HighVersion $R4.$R2"
;DetailPrint "
Description $R5"
;DetailPrint "
SystemStatus $R6"
;DetailPrint "
MaxSockets $R7"
;DetailPrint "
MaxUdpDg$R8"
;DetailPrint "
VendorInfo $R9"
;DetailPrint "
Connect return $8"
;DetailPrint "
***********************"

System::Free $7
System::Free $2

Goto done

DllNotOK:
MessageBox mb_ok "
The WinSock DLL is unacceptable"
Goto done

done:

Pop 
$R9
Pop 
$R8
Pop 
$R7
Pop 
$R6
Pop 
$R5
Pop 
$R4
Pop 
$R3
Pop 
$R2
Pop 
$R1
Pop 
$R0
Pop $9
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
Exch $8 ;Stack =  0 (conect to socket OK) or -1 (conect to socket not OK)

FunctionEnd 
kike_velez is offline   Reply With Quote
Old 16th June 2005, 13:10   #5
PleaseKING
Junior Member
 
Join Date: May 2005
Location: St.Petersburg, Russia
Posts: 3
Send a message via ICQ to PleaseKING Send a message via Yahoo to PleaseKING
Thanks a lot, that seems to be the one I need, will try that.
PleaseKING is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump