News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Which port for availability

Started by Farabi, December 22, 2012, 08:46:14 PM

Previous topic - Next topic

Farabi

Which port on Internet port I should talk when I want to check availability of a computer using winsock? Currently I used port 139. And is there a fast way to retrieve all IP address of active computers than loop through all IP address for checking their availablity.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Tedd

Ping is a standard for this exact purpose. If you want to implement it yourself, lookup "ICMP echo".

For checking on the local network, you can use a broadcast packet - all nodes will receive it, but only those that exist will reply, take their IP addresses from the replies.
Potato2

Farabi

Quote from: Tedd on December 24, 2012, 03:56:51 AM
Ping is a standard for this exact purpose. If you want to implement it yourself, lookup "ICMP echo".

For checking on the local network, you can use a broadcast packet - all nodes will receive it, but only those that exist will reply, take their IP addresses from the replies.

Sometimes ping is not working. My litle bro vaio laptop ports is all closed, so I cant check its availability. But if I access the DSL router I can have all the list of connected computers but I need to input the password through the telnet port. Maybe you have a simple way using the DSL router to retrieve all of the IP adress since my current job is maintaining the LAN again.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

Now I know all ports closed is not normal. It cannot discover another computer, and it cannot do data transfer through explorer. The only way to transfer data is only to port 80. I dont now what happened to my litle bro vaio laptop but after I reinstall it it fixed and worked again.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

six_L

this codes can check an available port in the somehost vlan.
.686p
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
include \masm32\include\masm32.inc
include \masm32\include\wsock32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\wsock32.lib

include \masm32\macros\macros.asm
DLG_MAIN equ 2000
IDC_EDIT_TEXT equ 100
IDC_EDIT_HOST equ 101
IDC_EDIT_PORT equ 102
IDC_EDIT_IP equ 103
IDC_BTN_START equ 201
IDC_BTN_STOP equ 202
IDC_BTN_CLEAR equ 204

TIMER_ID equ 999
WM_SOCKET equ WM_USER + 777

HOST_SIZE equ 256
TEXT_SIZE equ 500
ET_SIZE equ 10000
.DATA
ClassName db "IpScanClass", 0
AppName db      "IpScanner", 0
DlgName db "Dialog1", 0

LN db 13,10, 0
.DATA?
        hInst         HINSTANCE ?
hWin HWND ?

WSA WSADATA <?>
hSock SOCKET ?
sa sockaddr_in <?>

dwPort dd ?
IpEnd dd ?
host db HOST_SIZE dup (?)
SockOp dd ?
SockCl dd ?
Scanning dd ?

SCon dd ?
SRef dd ?
STim dd ?
SOth dd ?

text db TEXT_SIZE dup(?)
EditBuffer db ET_SIZE dup (?)
dwIP_addr_end dd ?
dwIP_addr dd ?
.CODE
Print PROC a: DWORD
invoke wsprintf, offset text,CTXT("%ld"), a
invoke MessageBox, 0, offset text, offset AppName, MB_OK
ret
Print ENDP
Refresh PROC
invoke SetDlgItemText, hWin, IDC_EDIT_TEXT, offset EditBuffer
invoke SendDlgItemMessage, hWin, IDC_EDIT_TEXT, EM_GETLINECOUNT, 0, 0
.if eax >= 17
sub eax, 17
invoke SendDlgItemMessage, hWin, IDC_EDIT_TEXT, EM_LINESCROLL, 0, eax
.endif
ret
Refresh ENDP
Put PROC txtptr: dword
invoke lstrcat, offset EditBuffer, txtptr
ret
Put ENDP
PutNum PROC num: DWORD
invoke wsprintf, offset text,CTXT("%ld"), num
invoke lstrcat, offset EditBuffer, offset text
ret
PutNum ENDP
AddText PROC txtptr: DWORD
invoke Put, txtptr
invoke Refresh
ret
AddText ENDP
EnableControls PROC

invoke GetDlgItem, hWin,IDC_BTN_START
invoke EnableWindow,eax, TRUE

invoke GetDlgItem, hWin,IDC_BTN_CLEAR
invoke EnableWindow,eax, TRUE

invoke EnableWindow, IDC_EDIT_HOST,  TRUE
invoke EnableWindow,eax, TRUE

invoke GetDlgItem, hWin,IDC_EDIT_PORT
invoke EnableWindow,eax, TRUE
ret

EnableControls ENDP
GetParams PROC

invoke GetDlgItemText, hWin, IDC_EDIT_PORT, offset text, sizeof text
invoke  atodw, offset text
mov dwPort,eax

mov eax,dwPort

.if (eax < 1 ) || (eax > 65536)
invoke MessageBox, 0, CTXT("Wrong the Port parameter !"), offset AppName, MB_OK + MB_ICONERROR
mov eax, FALSE
.else
invoke htons, dwPort
mov sa.sin_port, ax
mov eax, TRUE
.endif
ret

GetParams ENDP
GetHost PROC
local Rtflag:dword

mov Rtflag,FALSE
invoke GetDlgItemText, hWin, IDC_EDIT_HOST, offset host, HOST_SIZE
invoke Put, CTXT("Remote host: ") ;Frist Char
invoke inet_addr, offset host

.if (eax != INADDR_NONE) && (eax != 0)
mov sa.sin_addr, eax
mov Rtflag,TRUE
.else
invoke gethostbyname, offset host
.if eax != 0
mov eax, [eax+12]
mov eax, [eax]
mov eax, [eax]
mov sa.sin_addr, eax
mov Rtflag,TRUE
.endif
.endif
invoke gethostbyaddr, offset sa.sin_addr, 4, 0
.if eax != 0
mov eax, [(hostent ptr [eax]).h_name]
invoke Put, eax
.else
invoke Put, CTXT("-unknown-")
.endif
.if Rtflag==TRUE
invoke Put, CTXT(" [")
mov eax,sa.sin_addr
invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT("]")
invoke Put, offset LN
invoke Refresh
.endif
mov eax,Rtflag
ret

GetHost ENDP
GetLocalHost PROC

invoke gethostname, offset host,HOST_SIZE
.if eax != SOCKET_ERROR
invoke gethostbyname, offset host
.if eax!=0
push eax

; hostname
invoke Put, CTXT("Local host: ")
invoke Put, offset host
invoke Put, CTXT(" [")

pop eax
mov eax,[eax+12]
mov eax, [eax]
mov eax, [eax]

invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT("]")
invoke Put, offset LN
invoke Refresh
.endif
.endif
ret

GetLocalHost ENDP
ShowStat PROC
invoke Put, CTXT("-------- Statistics --------", 13,10)

invoke Put, CTXT("Ready ")
invoke PutNum, SockCl
invoke Put, CTXT("of ")
invoke PutNum, SockOp
invoke Put,CTXT(" attempts", 13,10)

invoke Put, CTXT("Connected: ")
invoke PutNum, SCon
invoke Put, offset LN

.if SRef != 0
invoke Put, CTXT("Refused: ")
invoke PutNum, SRef
invoke Put, offset LN

.elseif STim != 0
invoke Put, CTXT("Timed out: ")
invoke PutNum, STim
invoke Put, offset LN

.elseif SOth != 0
invoke Put, CTXT("Other: ")
invoke PutNum, SOth
invoke Put, offset LN
.endif
ret

ShowStat ENDP
ProcDlgMain proc hWnd,wMsg,wParam,lParam

mov eax,wMsg
.if eax == WM_INITDIALOG
m2m hWin,hWnd
.elseif eax == WM_COMMAND
.if word ptr [wParam] == IDC_BTN_START           
invoke GetDlgItemText, hWnd, IDC_EDIT_TEXT, offset EditBuffer, ET_SIZE
invoke GetParams
.if eax == 1
invoke WSAStartup, 0202h, offset WSA
.if eax == 0
invoke GetHost
.if eax == TRUE
invoke GetLocalHost

mov sa.sin_family, AF_INET
mov SockOp, 0
mov SockCl, 0
mov SCon, 0
mov SRef, 0
mov STim, 0
mov SOth, 0

invoke AddText, CTXT("Scan started...", 13,10)
invoke SetDlgItemText, hWnd, IDC_EDIT_IP, NULL
invoke EnableControls

mov eax,sa.sin_addr
bswap eax

and eax,0FFFFFF00H
inc eax
mov dwIP_addr,eax
or eax,0FFh
mov dwIP_addr_end, eax

mov Scanning, TRUE
invoke SetTimer, hWnd, TIMER_ID, 50, NULL

.else
invoke MessageBox, 0, CTXT("Unable to resolve hostname."), CTXT("Error"), MB_OK + MB_ICONERROR
invoke WSACleanup
.endif
.else
invoke MessageBox, 0, CTXT("WSA Error !"), offset AppName, MB_OK + MB_ICONERROR
.endif
.endif

invoke GetDlgItem, hWin,IDC_BTN_CLEAR
invoke EnableWindow,eax, FALSE

.elseif word ptr [wParam] == IDC_BTN_STOP           

invoke AddText, CTXT("stopped by user...", 13,10)
invoke GetDlgItem, hWin,IDC_BTN_START
invoke EnableWindow,eax, TRUE
jmp @ip_End

.elseif word ptr [wParam] == IDC_BTN_CLEAR           
mov byte ptr EditBuffer, 0
invoke SetDlgItemText, hWnd, IDC_EDIT_TEXT, NULL
invoke SetDlgItemText, hWnd, IDC_EDIT_IP, NULL
.endif

.elseif eax == WM_TIMER

invoke socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
.if eax != SOCKET_ERROR
mov hSock, eax
invoke WSAAsyncSelect, hSock, hWnd, WM_SOCKET, FD_CONNECT

.if eax == SOCKET_ERROR
jmp @error
.endif

mov eax,dwIP_addr
bswap eax
mov sa.sin_addr,eax
invoke inet_ntoa, eax
invoke wsprintf, offset text,CTXT("%s"), EAX
invoke SetDlgItemText, hWnd, IDC_EDIT_IP, offset text

invoke connect, hSock, offset sa, sizeof sa
.if eax == SOCKET_ERROR
invoke WSAGetLastError
.if eax != WSAEWOULDBLOCK
jmp @error
.endif
.endif
inc SockOp

mov eax, dwIP_addr
.if eax == dwIP_addr_end
@ip_End: invoke KillTimer, hWnd, TIMER_ID
mov Scanning, FALSE

.endif
inc dwIP_addr
.else
@error: mov eax,dwIP_addr
bswap eax ; eax= Local ip address
invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT(": socket error")
invoke Put, CTXT("[")
invoke WSAGetLastError
invoke PutNum, eax
invoke Put, CTXT("]")
invoke Put, offset LN
invoke Refresh
.endif

.if SockOp == 0
jmp Finish
.endif

.elseif eax == WM_SOCKET
mov eax,lParam
.if ax == FD_CONNECT
shr eax,16
.if ax == 0
inc SCon
mov eax,dwIP_addr
dec eax
bswap eax
invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT(" : CONNECTED")
invoke Put, CTXT(" [")
invoke PutNum, wParam
invoke Put, CTXT(" socket]")
invoke Put, offset LN
invoke Refresh

.elseif ax == WSAECONNREFUSED
inc SRef
.elseif ax == WSAETIMEDOUT
inc STim
.else
inc SOth
.endif
; Disconnect
invoke closesocket, wParam ; wparam = socket
inc SockCl
.if Scanning != TRUE
mov eax, SockCl
.if eax == SockOp
Finish:
invoke WSACleanup
invoke Put, CTXT("Scan finished.", 13,10)
invoke ShowStat
invoke Put, CTXT("=================", 13,10)
invoke Refresh
invoke EnableControls
.endif
.endif
.endif

.elseif eax == WM_CLOSE
.if Scanning != FALSE
invoke KillTimer, hWnd, TIMER_ID
.endif
invoke WSACleanup
invoke EndDialog,hWnd,NULL
.else
mov eax,FALSE
ret
.endif

mov eax,TRUE
ret

ProcDlgMain endp
Start:
invoke GetModuleHandle,NULL
invoke DialogBoxParam,eax,DLG_MAIN,NULL,offset ProcDlgMain,0
invoke ExitProcess,NULL

end Start


#include <\masm32\INCLUDE\resource.h>
#define DLG_MAIN 2000
#define IDC_EDIT_TEXT 100
#define IDC_EDIT_HOST 101
#define IDC_EDIT_PORT 102
#define IDC_EDIT_IP 103
#define IDC_BTN_START 201
#define IDC_BTN_STOP 202
#define IDC_BTN_CLEAR 204
#define IDC_STATICTEXT1 301
#define IDC_STATICTEXT2 302
#define IDC_STATICTEXT3 303
DLG_MAIN DIALOG 0, 0, 178, 180
STYLE DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "IpScanner to connect"
FONT 10, "MS Sans Serif"
{
CONTROL "www.yahoo.com", IDC_EDIT_HOST, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 28, 2, 146, 12
CONTROL "80", IDC_EDIT_PORT, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 28, 16, 24, 12
CONTROL "", IDC_EDIT_TEXT, "EDIT", ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL, 4, 30, 170, 135
CONTROL "Start", IDC_BTN_START, "BUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 4, 166, 26, 12
CONTROL "Stop", IDC_BTN_STOP, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 32, 166, 26, 12
CONTROL "Clear", IDC_BTN_CLEAR, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 148, 166, 26, 12
CONTROL "Host:", IDC_STATICTEXT1, "static", SS_LEFT | WS_CHILD | WS_VISIBLE, 4, 4, 18, 8
CONTROL "Port:", IDC_STATICTEXT2, "static", SS_LEFT | WS_CHILD | WS_VISIBLE, 4, 18, 19, 8
CONTROL "ScanIP:", IDC_STATICTEXT3, "static", SS_LEFT | WS_CHILD | WS_VISIBLE,90, 18, 28, 8
CONTROL "255.255.255.255", IDC_EDIT_IP, "EDIT", ES_LEFT | ES_AUTOHSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER, 119, 16, 55, 12
}
Say you, Say me, Say the codes together for ever.

Farabi

Quote from: six_L on December 31, 2012, 12:23:06 AM
this codes can check an available port in the somehost vlan.
.686p
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
include \masm32\include\masm32.inc
include \masm32\include\wsock32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\wsock32.lib

include \masm32\macros\macros.asm
DLG_MAIN equ 2000
IDC_EDIT_TEXT equ 100
IDC_EDIT_HOST equ 101
IDC_EDIT_PORT equ 102
IDC_EDIT_IP equ 103
IDC_BTN_START equ 201
IDC_BTN_STOP equ 202
IDC_BTN_CLEAR equ 204

TIMER_ID equ 999
WM_SOCKET equ WM_USER + 777

HOST_SIZE equ 256
TEXT_SIZE equ 500
ET_SIZE equ 10000
.DATA
ClassName db "IpScanClass", 0
AppName db      "IpScanner", 0
DlgName db "Dialog1", 0

LN db 13,10, 0
.DATA?
        hInst         HINSTANCE ?
hWin HWND ?

WSA WSADATA <?>
hSock SOCKET ?
sa sockaddr_in <?>

dwPort dd ?
IpEnd dd ?
host db HOST_SIZE dup (?)
SockOp dd ?
SockCl dd ?
Scanning dd ?

SCon dd ?
SRef dd ?
STim dd ?
SOth dd ?

text db TEXT_SIZE dup(?)
EditBuffer db ET_SIZE dup (?)
dwIP_addr_end dd ?
dwIP_addr dd ?
.CODE
Print PROC a: DWORD
invoke wsprintf, offset text,CTXT("%ld"), a
invoke MessageBox, 0, offset text, offset AppName, MB_OK
ret
Print ENDP
Refresh PROC
invoke SetDlgItemText, hWin, IDC_EDIT_TEXT, offset EditBuffer
invoke SendDlgItemMessage, hWin, IDC_EDIT_TEXT, EM_GETLINECOUNT, 0, 0
.if eax >= 17
sub eax, 17
invoke SendDlgItemMessage, hWin, IDC_EDIT_TEXT, EM_LINESCROLL, 0, eax
.endif
ret
Refresh ENDP
Put PROC txtptr: dword
invoke lstrcat, offset EditBuffer, txtptr
ret
Put ENDP
PutNum PROC num: DWORD
invoke wsprintf, offset text,CTXT("%ld"), num
invoke lstrcat, offset EditBuffer, offset text
ret
PutNum ENDP
AddText PROC txtptr: DWORD
invoke Put, txtptr
invoke Refresh
ret
AddText ENDP
EnableControls PROC

invoke GetDlgItem, hWin,IDC_BTN_START
invoke EnableWindow,eax, TRUE

invoke GetDlgItem, hWin,IDC_BTN_CLEAR
invoke EnableWindow,eax, TRUE

invoke EnableWindow, IDC_EDIT_HOST,  TRUE
invoke EnableWindow,eax, TRUE

invoke GetDlgItem, hWin,IDC_EDIT_PORT
invoke EnableWindow,eax, TRUE
ret

EnableControls ENDP
GetParams PROC

invoke GetDlgItemText, hWin, IDC_EDIT_PORT, offset text, sizeof text
invoke  atodw, offset text
mov dwPort,eax

mov eax,dwPort

.if (eax < 1 ) || (eax > 65536)
invoke MessageBox, 0, CTXT("Wrong the Port parameter !"), offset AppName, MB_OK + MB_ICONERROR
mov eax, FALSE
.else
invoke htons, dwPort
mov sa.sin_port, ax
mov eax, TRUE
.endif
ret

GetParams ENDP
GetHost PROC
local Rtflag:dword

mov Rtflag,FALSE
invoke GetDlgItemText, hWin, IDC_EDIT_HOST, offset host, HOST_SIZE
invoke Put, CTXT("Remote host: ") ;Frist Char
invoke inet_addr, offset host

.if (eax != INADDR_NONE) && (eax != 0)
mov sa.sin_addr, eax
mov Rtflag,TRUE
.else
invoke gethostbyname, offset host
.if eax != 0
mov eax, [eax+12]
mov eax, [eax]
mov eax, [eax]
mov sa.sin_addr, eax
mov Rtflag,TRUE
.endif
.endif
invoke gethostbyaddr, offset sa.sin_addr, 4, 0
.if eax != 0
mov eax, [(hostent ptr [eax]).h_name]
invoke Put, eax
.else
invoke Put, CTXT("-unknown-")
.endif
.if Rtflag==TRUE
invoke Put, CTXT(" [")
mov eax,sa.sin_addr
invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT("]")
invoke Put, offset LN
invoke Refresh
.endif
mov eax,Rtflag
ret

GetHost ENDP
GetLocalHost PROC

invoke gethostname, offset host,HOST_SIZE
.if eax != SOCKET_ERROR
invoke gethostbyname, offset host
.if eax!=0
push eax

; hostname
invoke Put, CTXT("Local host: ")
invoke Put, offset host
invoke Put, CTXT(" [")

pop eax
mov eax,[eax+12]
mov eax, [eax]
mov eax, [eax]

invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT("]")
invoke Put, offset LN
invoke Refresh
.endif
.endif
ret

GetLocalHost ENDP
ShowStat PROC
invoke Put, CTXT("-------- Statistics --------", 13,10)

invoke Put, CTXT("Ready ")
invoke PutNum, SockCl
invoke Put, CTXT("of ")
invoke PutNum, SockOp
invoke Put,CTXT(" attempts", 13,10)

invoke Put, CTXT("Connected: ")
invoke PutNum, SCon
invoke Put, offset LN

.if SRef != 0
invoke Put, CTXT("Refused: ")
invoke PutNum, SRef
invoke Put, offset LN

.elseif STim != 0
invoke Put, CTXT("Timed out: ")
invoke PutNum, STim
invoke Put, offset LN

.elseif SOth != 0
invoke Put, CTXT("Other: ")
invoke PutNum, SOth
invoke Put, offset LN
.endif
ret

ShowStat ENDP
ProcDlgMain proc hWnd,wMsg,wParam,lParam

mov eax,wMsg
.if eax == WM_INITDIALOG
m2m hWin,hWnd
.elseif eax == WM_COMMAND
.if word ptr [wParam] == IDC_BTN_START           
invoke GetDlgItemText, hWnd, IDC_EDIT_TEXT, offset EditBuffer, ET_SIZE
invoke GetParams
.if eax == 1
invoke WSAStartup, 0202h, offset WSA
.if eax == 0
invoke GetHost
.if eax == TRUE
invoke GetLocalHost

mov sa.sin_family, AF_INET
mov SockOp, 0
mov SockCl, 0
mov SCon, 0
mov SRef, 0
mov STim, 0
mov SOth, 0

invoke AddText, CTXT("Scan started...", 13,10)
invoke SetDlgItemText, hWnd, IDC_EDIT_IP, NULL
invoke EnableControls

mov eax,sa.sin_addr
bswap eax

and eax,0FFFFFF00H
inc eax
mov dwIP_addr,eax
or eax,0FFh
mov dwIP_addr_end, eax

mov Scanning, TRUE
invoke SetTimer, hWnd, TIMER_ID, 50, NULL

.else
invoke MessageBox, 0, CTXT("Unable to resolve hostname."), CTXT("Error"), MB_OK + MB_ICONERROR
invoke WSACleanup
.endif
.else
invoke MessageBox, 0, CTXT("WSA Error !"), offset AppName, MB_OK + MB_ICONERROR
.endif
.endif

invoke GetDlgItem, hWin,IDC_BTN_CLEAR
invoke EnableWindow,eax, FALSE

.elseif word ptr [wParam] == IDC_BTN_STOP           

invoke AddText, CTXT("stopped by user...", 13,10)
invoke GetDlgItem, hWin,IDC_BTN_START
invoke EnableWindow,eax, TRUE
jmp @ip_End

.elseif word ptr [wParam] == IDC_BTN_CLEAR           
mov byte ptr EditBuffer, 0
invoke SetDlgItemText, hWnd, IDC_EDIT_TEXT, NULL
invoke SetDlgItemText, hWnd, IDC_EDIT_IP, NULL
.endif

.elseif eax == WM_TIMER

invoke socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
.if eax != SOCKET_ERROR
mov hSock, eax
invoke WSAAsyncSelect, hSock, hWnd, WM_SOCKET, FD_CONNECT

.if eax == SOCKET_ERROR
jmp @error
.endif

mov eax,dwIP_addr
bswap eax
mov sa.sin_addr,eax
invoke inet_ntoa, eax
invoke wsprintf, offset text,CTXT("%s"), EAX
invoke SetDlgItemText, hWnd, IDC_EDIT_IP, offset text

invoke connect, hSock, offset sa, sizeof sa
.if eax == SOCKET_ERROR
invoke WSAGetLastError
.if eax != WSAEWOULDBLOCK
jmp @error
.endif
.endif
inc SockOp

mov eax, dwIP_addr
.if eax == dwIP_addr_end
@ip_End: invoke KillTimer, hWnd, TIMER_ID
mov Scanning, FALSE

.endif
inc dwIP_addr
.else
@error: mov eax,dwIP_addr
bswap eax ; eax= Local ip address
invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT(": socket error")
invoke Put, CTXT("[")
invoke WSAGetLastError
invoke PutNum, eax
invoke Put, CTXT("]")
invoke Put, offset LN
invoke Refresh
.endif

.if SockOp == 0
jmp Finish
.endif

.elseif eax == WM_SOCKET
mov eax,lParam
.if ax == FD_CONNECT
shr eax,16
.if ax == 0
inc SCon
mov eax,dwIP_addr
dec eax
bswap eax
invoke inet_ntoa, eax
invoke Put, eax
invoke Put, CTXT(" : CONNECTED")
invoke Put, CTXT(" [")
invoke PutNum, wParam
invoke Put, CTXT(" socket]")
invoke Put, offset LN
invoke Refresh

.elseif ax == WSAECONNREFUSED
inc SRef
.elseif ax == WSAETIMEDOUT
inc STim
.else
inc SOth
.endif
; Disconnect
invoke closesocket, wParam ; wparam = socket
inc SockCl
.if Scanning != TRUE
mov eax, SockCl
.if eax == SockOp
Finish:
invoke WSACleanup
invoke Put, CTXT("Scan finished.", 13,10)
invoke ShowStat
invoke Put, CTXT("=================", 13,10)
invoke Refresh
invoke EnableControls
.endif
.endif
.endif

.elseif eax == WM_CLOSE
.if Scanning != FALSE
invoke KillTimer, hWnd, TIMER_ID
.endif
invoke WSACleanup
invoke EndDialog,hWnd,NULL
.else
mov eax,FALSE
ret
.endif

mov eax,TRUE
ret

ProcDlgMain endp
Start:
invoke GetModuleHandle,NULL
invoke DialogBoxParam,eax,DLG_MAIN,NULL,offset ProcDlgMain,0
invoke ExitProcess,NULL

end Start


#include <\masm32\INCLUDE\resource.h>
#define DLG_MAIN 2000
#define IDC_EDIT_TEXT 100
#define IDC_EDIT_HOST 101
#define IDC_EDIT_PORT 102
#define IDC_EDIT_IP 103
#define IDC_BTN_START 201
#define IDC_BTN_STOP 202
#define IDC_BTN_CLEAR 204
#define IDC_STATICTEXT1 301
#define IDC_STATICTEXT2 302
#define IDC_STATICTEXT3 303
DLG_MAIN DIALOG 0, 0, 178, 180
STYLE DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "IpScanner to connect"
FONT 10, "MS Sans Serif"
{
CONTROL "www.yahoo.com", IDC_EDIT_HOST, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 28, 2, 146, 12
CONTROL "80", IDC_EDIT_PORT, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 28, 16, 24, 12
CONTROL "", IDC_EDIT_TEXT, "EDIT", ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL, 4, 30, 170, 135
CONTROL "Start", IDC_BTN_START, "BUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 4, 166, 26, 12
CONTROL "Stop", IDC_BTN_STOP, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 32, 166, 26, 12
CONTROL "Clear", IDC_BTN_CLEAR, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 148, 166, 26, 12
CONTROL "Host:", IDC_STATICTEXT1, "static", SS_LEFT | WS_CHILD | WS_VISIBLE, 4, 4, 18, 8
CONTROL "Port:", IDC_STATICTEXT2, "static", SS_LEFT | WS_CHILD | WS_VISIBLE, 4, 18, 19, 8
CONTROL "ScanIP:", IDC_STATICTEXT3, "static", SS_LEFT | WS_CHILD | WS_VISIBLE,90, 18, 28, 8
CONTROL "255.255.255.255", IDC_EDIT_IP, "EDIT", ES_LEFT | ES_AUTOHSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER, 119, 16, 55, 12
}


Thanks.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165