IP Code
Re: IP Code
Code: Select all
Structure CmdP_STARTUPINFO
cb.l
lpReserved.l
lpDesktop.l
lpTitle.l
dwX.l
dwY.l
dwXSize.l
dwYSize.l
dwXCountChars.l
dwYCountChars.l
dwFillAttribute.l
dwFlags.l
wShowWindow.w
cbReserved2.w
lpReserved2.l
hStdInput.l
hStdOutput.l
hStdError.l
EndStructure
Global proc.PROCESS_INFORMATION, start.CmdP_STARTUPINFO, sa.SECURITY_ATTRIBUTES, hReadP.l, hWriteP.l, lngBytesread.l, strBuff.s=Space(256)
Procedure.s Rd_cmd(comnd_send.s)
sa\nLength =SizeOf(SECURITY_ATTRIBUTES)
sa\bInheritHandle = 1
sa\lpSecurityDescriptor = 0
ret = CreatePipe_(@hReadP, @hWriteP, @sa, 0)
If ret = 0
MessageRequester("Information", "CreateP failed. Error: ",0)
End
EndIf
start\cb = SizeOf(CmdP_STARTUPINFO)
start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES
start\hStdOutput = hWriteP
start\hStdError = hWriteP
ret = CreateProcess_(0, comnd_send, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc)
If ret <> 1
MessageRequester("Information","File Or command not found", 0)
End
EndIf
ret = CloseHandle_(hWriteP)
mOutputs.s = ""
While ret<>0
ret = ReadFile_(hReadP, strBuff, 255, @lngBytesread, 0)
If lngBytesread>0
mOutputs = mOutputs + Left(strBuff, lngBytesread)
EndIf
Wend
ret = CloseHandle_(proc\hProcess)
ret = CloseHandle_(proc\hThread)
ret = CloseHandle_(hReadP)
ProcedureReturn mOutputs
EndProcedure
If CreateFile(0, "IP.txt")
WriteString(0, Rd_cmd("ipconfig"))
CloseFile(0)
EndIf
Delay(10)
RunProgram("IP.txt")
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Re: IP Code
This is what I used for an IP Validation system, it's since been abandoned.
Code: Select all
InitNetwork()
UserIPViewer$="http://h3x0r.ath.cx/Sonstiges/ShowMyIp12.php"
UserIP$ = StringField(GetHTTPHeader(UserIPViewer$), 2, Chr(34))
Debug UserIP$▓▓▓▓▓▒▒▒▒▒░░░░░
Re: IP Code
Thanks to you both. You have been most helpfull
Re: IP Code
@SFSxOI : nice code. However that is returning the internal IP address assigned by my router and not the external one. Any way of modifying your code? Nituvious' code gives the correct external IP address.
I may look like a mule, but I'm not a complete ass.
Re: IP Code
Your PC can not know its public IP adress if it is behind a NAT, as it cannot know how the nat translates the adress. The only option is to find a public machine on the internet which returns the IP adress to your program.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: IP Code
I understand; I figured that was probably the case.blueznl wrote:Your PC can not know its public IP adress if it is behind a NAT, as it cannot know how the nat translates the adress. The only option is to find a public machine on the internet which returns the IP adress to your program.
I may look like a mule, but I'm not a complete ass.
Re: IP Code
Well, Nituvious is getting his from an external source which means a dependance on the external source to tell you what you want to know. I haven't tried that with my code but its an idea and a good question.srod wrote:@SFSxOI : nice code. However that is returning the internal IP address assigned by my router and not the external one. Any way of modifying your code? Nituvious' code gives the correct external IP address.
Code: Select all
replace the line:
WriteString(0, Rd_cmd("ipconfig"))
with
WriteString(0, Rd_cmd("route print"))
Sort of interesting, now i want to play around some and figure something out.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
-
UserOfPure
- Enthusiast

- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: IP Code
Nope, not at all.SFSxOI wrote:you will get a whole bunch of info but one of those i think will be your external IP address
Re: IP Code
OK, then its not "WriteString(0, Rd_cmd("route print"))"
I was just guessing anyway, i just got around to trying it also and your correct, so thats not it. I don't think you can do this via a command prompt, but I seem to remember something from a while back, around the win95 days, that by manipulating some commands you could do that but i just don't remember right now. Oh well.
EDIT: Oh wait, i remember now, it was telnet via command prompt. You could try to telnet (via cmd prompt) into some mail servers and when you try to connect they respond with the IP your connecting from which is the external IP address because thats what they would see. Dont know if it works anymore though, I would think not with all the focus on security.
I was just guessing anyway, i just got around to trying it also and your correct, so thats not it. I don't think you can do this via a command prompt, but I seem to remember something from a while back, around the win95 days, that by manipulating some commands you could do that but i just don't remember right now. Oh well.
EDIT: Oh wait, i remember now, it was telnet via command prompt. You could try to telnet (via cmd prompt) into some mail servers and when you try to connect they respond with the IP your connecting from which is the external IP address because thats what they would see. Dont know if it works anymore though, I would think not with all the focus on security.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Re: IP Code
try this but you can't expect the host to keep this active
To host it h\your self just put this up on your website and save it as .php
Code: Select all
Declare.s GetURL(mUrl.s)
Procedure.s GetURL(mUrl.s)
Static bonline.i,gServerID.i
Protected mHost.s,mFile.s,Header.s,sOut.s,*buffer
*buffer = AllocateMemory(1200)
i = FindString(mUrl,"/",1)
If i
mFile = Right(mUrl,Len(mUrl)-i)
mHost = Left(mUrl,i-1)
Else
mHost = mUrl
mfile = mUrl
EndIf
If bOnline = 0
gServerID = OpenNetworkConnection(mHost,80)
If Not gServerID
MessageRequester("Network Problem","Can't establish connection")
EndIf
EndIf
Timeout = ElapsedMilliseconds() + 5000
If gServerID
Header = "GET /"+ mFile + " HTTP/1.1"+#CRLF$
Header + "Host: "+ mHost + #CRLF$+#CRLF$
SendNetworkData(gServerID,@Header,Len(Header))
Repeat
Delay(2)
Until NetworkClientEvent(gServerID) = #PB_NetworkEvent_Data And ElapsedMilliseconds() < Timeout
If ElapsedMilliseconds() < Timeout
Repeat
lt = ReceiveNetworkData(gServerID,*Buffer,1200)
sout + PeekS(*Buffer,lt)
Until DataLength = 0
EndIf
pos = FindString(Sout,#CRLF$ + #CRLF$,1)
If pos <> 0
pos+3
sout = Right(Sout,Len(sout)-pos)
EndIf
CloseNetworkConnection(gServerID)
EndIf
FreeMemory(*Buffer)
ProcedureReturn sOut
EndProcedure
InitNetwork()
Debug GetUrl("ipecho.net/plain.php")
Code: Select all
<?php
echo $_SERVER['HTTP_REFERER'];
?>
Last edited by idle on Mon Jan 18, 2010 5:07 am, edited 1 time in total.
Re: IP Code
idle, your code drops the first number of the returned IP address. For example;
75.66.198.25 will come bck as 5.66.198.25 < the 7 is missing. I had to change this to get it to display correctly:
'
75.66.198.25 will come bck as 5.66.198.25 < the 7 is missing. I had to change this to get it to display correctly:
'
Code: Select all
If pos <> 0
pos+3 ; < changed from 4 to 3
sout = Right(Sout,Len(sout)-pos)
EndIf
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Re: IP Code
thanks edited post



