i just wondered; is it possible to get the IP address of localhost using MASM? Well i suppose it must be ... anyway, what API's would i need to take a look at to learn how to do this? thanks. skud.
Posted on 2001-05-01 13:39:00 by skud
localhost is a psudonym for 127.0.0.1 and is usually assigned/associated in the Hosts file, but it may not be. :D It may be in the registry or defaulted in code unless overridden. I never did test to see if the extension of the Hosts file matters. (search for "hosts", see also "Lmhost" 127.0.0.1 is a special loopback address.
Posted on 2001-05-01 14:59:00 by SFinegan
Easy - you need to use the WinSock 1.1 API's to call gethostaddr etc. and this will enable you to get IP's and do internet related functions. Get the help/word doc on it either on win32asm or have a hunt around through the other links for the document. Also there are demos of how to actually code it on win32asm and also follow the links to find demos elsewhere too. There is a mail client program on my site with src that can be used to work it out as well : http://james.ezylink.net.au (called Simple Mailer) James
Posted on 2001-05-02 01:42:00 by James
SFineGan- i know localhost is 127.0.0.1 :P what i meant was the IP address of the computer the program is running on. thanks anyway. -James thanks alot, i'll take a look at it.
Posted on 2001-05-02 12:29:00 by skud
ok. i have now written a little prog that gets the ip address of the local computer. however it returns the network ip address whether i am on the internet or not. how do i get my internet ip address? the way i get the ip address is by getting the computers name and then using that to use gethostbyname. in fact its probably easier with my code... .386 .model flat, stdcall option casemap:none include C:\masm32\include\windows.inc include C:\masm32\include\kernel32.inc include C:\masm32\include\user32.inc include C:\masm32\include\wsock32.inc includelib C:\masm32\lib\user32.lib includelib C:\masm32\lib\kernel32.lib includelib C:\masm32\lib\wsock32.lib .data caption db "Current IP Address",0 errtxt db "Invalid Host Name!",0 wsaerrtxt db "WSAStartup ERROR",0 host db 128 dup (0) IPAD dd ? wsadata WSADATA <> .Code Main: invoke WSAStartup,101h,ADDR wsadata cmp eax,0 jne wsaerr invoke GetComputerName,ADDR host,128 invoke gethostbyname,ADDR host cmp eax,0 je error mov eax, mov eax, mov eax, mov IPAD,eax invoke inet_ntoa,IPAD invoke MessageBox,0,eax,ADDR caption,MB_OK jmp Exit error: invoke MessageBox,0,ADDR errtxt,ADDR caption,MB_OK jmp Exit wsaerr: invoke MessageBox,0,ADDR wsaerrtxt,ADDR caption,MB_OK Exit: invoke WSACleanup invoke ExitProcess,0 End Main
Posted on 2001-05-03 10:59:00 by skud
skud: take a look at this post (quite old, code tags where not available yet :): gethostbyname (Winsock). Thomas
Posted on 2001-05-03 12:10:00 by Thomas
Ahoy, If I don't tell the true, correct me. Normaly our LocalHost is 127.0.0.1, it is a Loopback. If we own more than one Network Interface Card (NIC) adapter we have more than one IP address. If a Network Interface Card (NIC) is avaible and a static IP address is asigned, for example 192.168.1.20 (Class C), this is the IP address of our LocalHost. If we choose automatic assigned IP address and a DHCP Server is not avaible (on win2k) Windows assign an APIPA address. This one comes from a pool of reserved addresses. The APIPA address range is 169.254.x.x. For example if we get the IP address 169.254.100.15 it is an APIPA address, our Local Host. On a Local NetWork for games we normaly use use WINS NETBIOS and the 'lmhost, host' files. In this case we assign a static address in files which must be identical on every Pc. If not, no playing. But I'm not a player ;), do you know Prof. Tim and his inc. machine ? It runs fine on my P1 233 MHz. Ok.... A PPP connection (Internet) is also an Adapter. On a Call by Call provider normaly we choose the automatic assigned IP address, we get it from our provider. At least I must say it is a long and damned story ... You can download a net utility with source from my website : http://www.geocities.com/ge2001 Thank you. so long Test
Posted on 2001-05-03 15:57:00 by Test Department