WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Get IP Address

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Using Internet Winsock Extender Method to get your Dialup IP address

Keywords: 	   MAC Get IP address

I was playing with the new Internet Extender and I noticed that it is very easy to determine what IP address you were assigned when you called into Internet using DialUp Networking. I am including it here. All that I did was make a socket connection to a port on an Ftp Server and then use "wxGetInfo" to find out what my IP address is, and I then stripped off the port info that comes with the IP address. Here's my example code:
AddExtender("wwwsk34I.dll")
FtpServer=AskLine("FTP Server To Connect to.", "Enter a known ftp server that I can connect to.", "")
talksocket=sOpen()
ret=sConnect(talksocket,"%FtpServer%","ftp")
portaddr=wxGetInfo(1,talksocket)
sClose(talksocket)
ipaddr=ItemExtract(1,portaddr,":")
If ipaddr!="0.0.0.0"
  Message("IP Address", ipaddr)
Else
  Message("Try again with a different Server address!","I could not get through to %FtpServer%.")
EndIf
Exit

Slightly different variation (to get IP Address):

Using the Internet Extender, you can make a connection to a known server and then you can look up your own address from this connection. It does not use any special Windows programs to do this. This works *real* good.

:GetIpAddress

:ConnectToHost 

GoSub DebugHook

  ;Get the Ip Address for this machine by opening and connecting

  ;a socket to a known Server.

  talksocket=sOpen()

  ret=sConnect(talksocket,"%host%","ftp")

  ;This is where we get the IpAdress with the Socket number.

  IpAddress=wxGetInfo(1,talksocket)

  ;Find the colon which is the charecter used to 

  ;parse the Ip Adress from the Socket Number.

  colon= StrIndex(IpAddress, ":", 0, @FWDSCAN)-1

  ;Strip off the Socket Number.

  IpAddress=StrSub(IpAddress, 1, colon)	 



  LoopCnt=1

  Status=@FALSE

  While ( (LoopCnt<WaitForTime)&& (Status==@FALSE) )

    Status=sOK2Recv(talksocket,1)

    LoopCnt=LoopCnt+1

    TimeDelay(1)

  EndWhile

  GoSub DebugHook



  If (sOk2Recv(talksocket,1)==@FALSE) Then GoTo ConnectToHost



  ;All done with this Socket

  sClose(talksocket)

GoSub DebugHook

Return

Article ID:   W12652
Filename:   Get IP address - Internet Extender Method.txt
File Created: 2001:03:01:15:08:22
Last Updated: 2001:03:01:15:08:22