Hey guys Im working on a ftp client (most of you im sure you already know) and in order to do that I think I may need the ip of the address to login to the server instead of just a web address (I know I can type in the addie but I have to convert it in my program). Does anyone know how to convert web addresses into ips? Any help is appreciated thanks.

RIF
Posted on 2002-09-04 20:48:05 by resistance_is_futile
For winsock 2: getaddrinfo
For winsock 1: gethostbyname
Posted on 2002-09-05 00:29:23 by Qweerdy
ok this is what i tried but its not working:



include windows.inc
include user32.inc
include kernel32.inc
include shell32.inc
include comctl32.inc
include comdlg32.inc
include wsock32.inc

includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
includelib comctl32.lib
includelib comdlg32.lib
includelib wsock32.lib

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.const

IDM_FILE_EXIT equ 10001
IDM_HELP_ABOUT equ 10101
IDC_BTN1 equ 1001
IDC_EDT1 equ 1002
IDC_EDT2 equ 1004

.data

ClassName db 'DLGCLASS',0
MenuName db 'MyMenu',0
DlgName db 'MyDialog',0
AppName db 'Dialog as main',0
AboutMsg db 'MASM32 RadASM Dialog as main',13,10,'Copyright ? MASM32 2001',0
Error db 'Could not start winsock 1.1',0
ok db 'ok',0
ip2 db 'http://ftp.hostultra.com',0
ip3 db 0,0

.data?

hInstance dd ?
CommandLine dd ?
hWnd dd ?
websitename dd ?
WSAData WSADATA <?>
ip dd ?



and my code





.elseif wParam==1001
invoke GetDlgItemText,hWin,IDC_EDT1,addr ip3,sizeof ip3
invoke SetDlgItemText,hWin,IDC_EDT1,addr ip3
invoke gethostbyname, addr ip3
mov eax,[eax+12]
mov eax,[eax]
mov eax,[eax]
invoke inet_ntoa,eax

invoke SetDlgItemText,hWin,IDC_EDT2,eax
.endif



For some reason this isnt working anyone know why?
Posted on 2002-09-06 17:27:36 by resistance_is_futile
What you have asked for is code which resolves a DNS to IP.
Here ya go :)
just hand this procedure the port and addres of host string.
It doesnt care if the host name is an ip string or dns string,
either way it will resolve the correct IP and connect to the host.
Feel free to modify this code if necessary.

;************************************************
;* *
;* Open a new TCP connection given Host amd Port*
;* *
;************************************************
MakeConnection PROC hwnd:DWORD,lpHost:DWORD,Port:DWORD
invoke socket,PF_INET,SOCK_STREAM,0
.if eax!=SOCKET_ERROR
mov sock,eax
invoke inet_addr,lpHost ;assume its an ip string
.if eax==INADDR_NONE
invoke gethostbyname,lpHost ;ok so its a domain string
.if eax==NULL
xor eax,eax
ret
.endif
mov eax,
mov eax,
mov eax,
.endif
mov SocketAddress.sin_addr,eax
mov SocketAddress.sin_family,AF_INET
invoke htons,Port ; port in network byte order
mov SocketAddress.sin_port,ax
invoke WSAAsyncSelect,sock,hWnd,WM_SOCKET,\ ; We choose to receive notification about successful connection,
FD_CONNECT or FD_READ or FD_CLOSE ; incoming data, and when the socket is closed
invoke connect,sock,addr SocketAddress,sizeof SocketAddress
.if eax==SOCKET_ERROR
invoke WSAGetLastError
.if eax!=WSAEWOULDBLOCK
invoke MessageBox,HWND_DESKTOP,addr szBAD,lpHost,MB_OK
mov eax,FALSE
ret
.endif
.endif
mov eax,TRUE
ret
.endif
mov eax,FALSE
ret
MakeConnection ENDP
Posted on 2002-09-06 22:24:58 by Homer
resistance_is_futile:

The mistake you made is in the host name. You shouldn't include the http:// part, that's just the protocol used to get the files and winsock doesn't know or care about that.
Posted on 2002-09-07 03:01:15 by Qweerdy
yes I have tried not entering http://.. Doesnt work. I still get an error. See the reason I was wanting to do this in the first place is because I thought that in order to connect to the server to d/l files from the ftp server, I had to have the server ip and port number but I guess thats wrong because it connects fine but my ftp program wont download the file. Like say I want to connect to ftp.geocities.com. It connects just fine but when i go to download a file, it screws up and doesnt download the file. so i figured it was reading the server wrong and required an ip. But now homer answered that question so I dont know where to go from here.. Lol maybe its something to do with my ftpgetfile command. I dunno. Im kind of stumped on this... :( :confused: :confused: :confused:
Posted on 2002-09-07 10:33:04 by resistance_is_futile