I need to retrieve the local (not server) machine name on an intranet web application. After a lot of searching, it looks like the below should work...
Dim Name As String = (Dns.GetHostEntry(Request.ServerVariables("REMOTE_HOST")).HostName)
However, this returns the error "No such host is known". Any ideas where I'm going wrong here?
Thanks
Turns out this wasn't working because we didn't have reverse lookup configured on our DNS. Since configuring this, it's now working as intended
I don't know why your statement isn't working but I use
Dim Hostname as string = System.Net.Dns.GetHostName
which you may fine useful.
Related
Currently deploying PostgREST in AWS. When I use Fargate and just hardcoded type in the environment variables for the connection string, the machine works like a charm.
However I recently replaced these values with secrets. In the secret I copy-pasted the entire string in the value and in the environment variable I set the source from "Value" to "ValueFrom".
So the value now is:
postgres://<myuser>:<mypass>#<amazon-rds-instance>:5432/<db>
When I use this connectionstring directly in the environment variable I can easily connect, so I know the information is correct.
The logs come back with the following error:
{"details":"missing \"=\" after \"{\"postgrest_db_connection\":\"postgres://myuser:mypass#amazon-rds-instance:5432/db\"}\" in connection info string\n","code":"","message":"Database connection error"}
I also checked I have no characters in the string that need to be escaped. What can I be missing here?
So I figured it out. Unfortunately this line was it:
It is only supported to inject the full contents of a secret as an environment variable. Specifying a specific JSON key or version is not supported at this time.
This means that whenever you use the secrets as ValueFrom setting in the environment variables (when working with Fargate), the entire secret's value gets copy-pasted.
I tested this using a secret for the PostgREST schema variable. I got back the value:
{'PGRST_SCHEMA_URL': 'public'}
Whilst I was expecting it to be just:
public
This is why the configuration went bad as well. Thanks everyone for searching.
I've been having a heck of a time trying to get this to work. I wrote both a service and a form application in VB.NET, both of which need to access a registry key to locate a computer that has my database on it. In the forms app it works great, but the service does not. I thought it was a permissions problem so I checked permissions on the server (Windows 2008) and they were fine - I even went as far as to run the service as the admin in case that was the problem but still no joy. Is there something wrong with my code?
I have tried ways to access the registry. The first method just sets the server variable to nothing and the second method the 'rk' variable ends up being nothing (telling me that it cannot even locate the sub key):
Dim server As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\EPS\XPV", "Server", Nothing)
and the second one is:
Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey("\SOFTWARE\EPS\XPV")
The service itself starts up just fine because I'm getting my log messages right after these lines that tell me the value is blank so it just comes down to figuring out why I cannot access the registry in the service even though I can in the forms app.
Either look under HKLM\SOFTWARE\Wow6432Node for your keys/values, or compile your application as 64bit.
How can you change your IP Address using visual basic please? I havnt been able to find anything useful anywhere so i was just wondering if I could get some help on here?
Im not onabout the external Ip address. I know that cannot be changed(I have a static one from my isp.) Im onabout changing the internal ipaddress... for example changing from: 192.168.1.150 to 10.0.0.125 –
Thanks
Chris
You could use some Windows scripting. It gets a little messy but you could create the script in VB.Net, write it to your hard drive and then execute it. When done, you can delete the script.
Here is an example of a script that changes the IP Address (and some other related fields):
http://www.wincert.net/forum/topic/40-change-ip-configuration-via-vb-script/
Then, you would execute it in VB.Net by calling
Process.Start("<The path of your .vbs file here>")
Good luck.
Your IP Address is leased to you via your ISP when you go online - you can't just "change it". If your ISP uses Dynamic IP leasing, you can switch off your router/modem for around 5 minutes, and reconnect - at which point you'll receive a new IP.
The only way to replicate this via VB would be to disconnect the user from a modem-based service within your application. But in this case, I'd hazard a guess that clicking the "disconnect" button would be an easier solution for the user.
you may not need to write any script to do this. And you dont need 2 network adapters as the only way to do this. in windows the network adapter can be assigned several IP addresses at the same time. go into network properties ipv4 tcp/ip settings advanced. you can put several ip addresses and masks. so if you have one pc but are using 2 different networks, just put 2 addresses in, then whichever network is connected use it normally.
if you have a network gadget like a new router and its on 192.168.0.200 and you know its going to be set to 10.1.1.x after you login, assign the computer 2 IPs like 192.168.0.100 and then 10.1.1.100.
This would be easier if I were able to have the external computer get its own name and just pass it to a web service as a variable, but I'm not able to do that right now. There are a variable number of computers from several different entities that regurarly access a web service on one of our servers. Changing only some VB.Net code on the server and nothing at all on any of those external computers, how would I be able to get their names programmatically in VB.Net? Thanks!
EDIT: Some of the answers look like they're designed to get the IP of either the server, the server's router, or something else along those lines. Maybe I'm just misreading the code or something, but I was talking about getting the names of client, external computers who try to access a webmethod on the server, using the webmethod's code to do so.
If there is no address translation and computers has DNS entries:
Dim ip As String = System.Web.HttpContext.Current.Request.UserHostAddress
Dim name as String = System.Net.Dns.GetHostEntry(ip).HostName()
System.Net.Dns.GetHostAddresses(My.Computer.Name)(5).ToString
Quick solution for getting external IP in VB.Net
Dim sIp As String
Dim webClient As System.Net.WebClient = New System.Net.WebClient()
sIp = webClient.DownloadString("http://lbb.ie/ip.php")
And that's it It is my own php file on my own server so go ahead :) Enjoy
I want to host a web server and want to use VBA to do it. Is this possible? I'm just doing this to prove someone wrong and really want to make this program.
So is it possible to make a really simple web server (just listens for get requests)? Help would be very much appreciated.
EDIT
I'm trying something like this
Sub startServer()
Set wunsock = CreateObject("OSWINSCK.Winsock")
wunsock.LocalPort = 80
wunsock.Listen
End Sub
Sub wunsock_ConnectionRequest(ByVal requestID As Long)
If sockMain.State <> sckClosed Then
sockMain.Close
End If
sockMain.Accept requestID
End Sub
Private Sub wunsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
sockMain.GetData strData, vbString
txtStatus.Text = txtStatus.Text & _
strData & vbCrLf
End Sub
However it doesn't work?
Although this is a rather old question, I'd still like to mention that I built an Excel hosted REST webserver using plain VBA macros and some Winsock C calls, as proposed by Daniel A. White.
I added this as an answer instead of a comment, since it's built as a modular library, so you can adjust it to your needs, and others might need exactly this kind of library. It can serve both worksheets, basic files and also create custom hooks using an IWebController to listen on specific routes (which was mentioned by OP in a comment):
http://github.com/michaelneu/webxcel
To use it, you'll have to either import the classes/modules into your workbook, or let the build script create a new one for you. See Main.bas on how to start the server from within VBA.
http://www.ostrosoft.com/oswinsck.asp#inst
is a winsock type of library which can be used from VBA. It is possible to do what you are looking to do though is not the most efficient thing to do.
I do applaud your tenacity hope it works out for you.
I'm not sure I fully understand the question. Generally, you don't "host a web server", you host a web site.
But if you can do TCP sockets with VBA, then you can make an incredibly simple web server by following the HTTP standard protocol.
Edit: based on your comment, yes you can make a simple web server as long as you can open up a TCP socket.
Well, at the risk of violating the spirit of the question, you can always use VB's support for library functions and just create a library binding to one of a number of C-language web server options (such as http://www.acme.com/software/micro_httpd/, http://www.gnu.org/software/libmicrohttpd/ or http://code.google.com/p/mongoose/). You'd have to make DLLs out of the selected web server but that is reasonably easily done and this will work just fine in VBA.